Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Working on an MVC application. I have hundreds of users. Currently I'm trying to give some of our top users (maybe 10) a discount if they log-in through their assigned work-place e-mails. The price break is shown in the Search result, Product page, Shopping Cart, and Checkout page. I had to work on this quickly to hack it for the holiday season, so currently the way I am doing this is something like this:
ProductDetails.aspx
if (user == "at#at.com") {
Product. Price * 20
}
else {
Product.Price
}
As you can see, this works for now, however I'd have to do this for all 4 pages, and as our discounted users increase, this may become too long and mundane. I'm looking at a way to go around having such a long if/else statement, and was wondering if it makes sense to use a stored procedure instead or a method?
I would suggest to add a discount field to the user table or any appropriate table in the database and save the discount info there. You can also create a new table that holds the discount information tied up to the different users and manage to return the discount value instead of going through an if/else statement.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to programming an schedule in C# where I want to show all my tasks, for example:
01-20-2018 at 3pm meeting with boss. And have a question:
Should I create a table "task" where i save the date my id and boss id?
Would it overload the dB?
I need some tips, thank you!
How many interlocutors (bosses) will you have ? Certainly more than one.
I suggest you should have one table for each purpose :
A task_table for tasks with an ID_Task as primary key, Detail field, delay field, status field and son on.
A target_table for the targets which is/are involved in the task with an ID_target (primary key) with a name field, first name field, company field, observation field and whatever field you need.
And you link this two tables in an another one :
Rendezvous_table, with Id_rendezvous (primary key), datetimestamp field, Id_Task field, Id_target field and observation_field for observation on rendezvous.
This can be a good start. Beware the relations one to multiple, one to one, multiple to multiple. Multiple task for a same rendez-vous, only one interlocutor for one rendez-vous or multiple...
Hope it helps.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Let's suppose we have 2 tables:
Person
ID
Name
Nationality_ID (FK)
Nationality
ID
Name
With EF, in what contexts does it make sense and is correct to use each of the options below to add a nationality to a person? What is the different between them? What is the faster and the slower?
Option 1:
TheNationality.persons.Add(ThePerson);
Option 2:
ThePerson.nationality_id = TheNationality.id;
Option 3:
ThePerson.nationality = TheNationality;
If Person is the root of your aggregate and the focus of your application, most likely option 2 and option 3 make sense. Of those, option 3 is the more useful if you need to do additional domain logic based upon information in your nationality. Option 1 makes sense if the focus of your application is about nationality.
None of these methods is mutually exclusive. If you query and manipulate the objects from both perspectives, you can use options 1/3 or 1/2.
The resulting insert/update would be the same in all cases. Unless it is necessary to get TheNationality entity for some other reason, you could skip the read to obtain that and just assign the ID if you have it:
ThePerson.nationality_id = someNationalityIDVariable;
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to determine where to write the business logic in application level or database server level. For example if I have simple procedure which sum the total price.What is the difference between to call the procedure with the logic to sum all of them and in application level to iterate each entity and make total sum after calling select *
Database level:
SELECT
SUM(sod.UnitPrice)
FROM Sales.SalesOrderDetail AS sod
OR
Application level:
foreach (var person IN context.GetAllPpl())
{
price += person.price;
}
What is the best approach for performance view of point ?
If your only goal here is to get the sum of UnitPrice, it's much more efficient to do the summation in your SQL query. This will always select exactly one row and one column, rather than every row and every column.
SELECT
SUM(sod.UnitPrice)
FROM Sales.SalesOrderDetail AS sod
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I currently have a mysql data table that fills up when people complete a form. I then have my visual studio c# bot pull this data and do what I want. The table numbers the table using integers that increase by 1 each time. My bot looks in the table for id 1 and adds it.
The problem I have is that once my bot completes what someone wants and deletes the data, it does not recognize to go onto the next one since that id is not 1 and something else, like 2. I tried to have my c# bot add 1 to a variable each time and then have that variable represent the id so that every time the bot completed something it would go onto the next id. The problem with this was that every time the bot completed with one person the variable was reset back to 1. I am stuck now and can't figure out what to do. Any help would be great.
This is currently the string I use "select name from names where id = 1". If I can somehow instead of having the id = 1 and have it look for the next lowest id in my table then that would work.
Edit: Actually I think I figured out how to have the last added id be used. I will post it if I find it.
In MySQL, if you want the lowest ID then you could do something like this:
SELECT
Name
FROM
Names
ORDER BY ID
Limit 1
Is that what you are looking for?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i'm looking to implement a similar thing to stackoverflow badges. you could also equate them to achievements in games.
but am not sure how to design the database/code/tracking for them.
i get what i should do for badges such as:
Altruist × 1456 First bounty you manually awarded on another person's question
because they are a one time event, but how to handle others such as:
Analytical × 16389 Visited every section of the FAQ
Electorate × 1783 Voted on 600 questions and 25% or more of total votes are on questions
Outspoken × 188 Posted 10 messages in chat that were starred by 10 different users
etc...
how to handle them, how to keep track of progress for each, etc... is there a tutorial or something that can help me figure out a design pattern for them?
For the given examples, there are essentially two mechanisms you are going to need.
I don't know how it's done on SO, this is just a suggestion of a solution.
Let's look at 'Analytical' first. You are going to have to record by means of a simple flag when a user visits a particular area in the FAQ. Let's envisage a DB table with a field for each FAQ section and a user ID. This starts off as "N" (or 0, or however you want to represent your flag). When a user visits that area, you call code to flip that field to "Y". When all fields are "Y" then you can award that badge.
As for 'electorate' and 'Outspoken', you can retrieve this information by means of a query on your existing data, assuming the queries themseves are not too burdensome. You are going to need to consider when to run these checks. This essentially boils down to two options.
1) When the an action is performed that might get a badge awarded (i.e. visit section of FAQ, Vote on a Question, Question starred by someone else)
2) Periodically (hourly, daily, etc) run a check for all your badges against current data.
Bear in mind that badges are one-way in Stackoverflow, so if you are wanting to be equivalent then you don't have to consider logic to 'un-award' badges.