TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Fabiola Martinez
NA
9
493
How to improve the functionality of this code in the face of new requi
Apr 9 2021 4:26 AM
Hi, I'm working with asp.net mvc c#. I have a form the allows users to register absences.
This form has three fields, a DropDownList with the list of reasons for absence (Illness, Study day, Other reason), date (the system takes the date) and description. But depending on the selected item it is validated for example. If the user selects the Illness item, it shows another DropDownList with the items (Abdominal Pain, Fever) and if it is by Study Day, they are allowed to select a date but with the restriction of notifying the absence of it 5 days in advance. If the user selects Other Reasons, another DropDownList is shown with the following items (Free Day, Moving) with the restrictions, for Free Day it should only be allowed between the 1st to the 5th of each month, after those days it should no longer allow record an absence. For Moving three days in advance, the absence must be registered.
This is my code
public
bool
CreateAbsence (Absence absence)
{
/*Id Reason Study Day = 2*/
if
(absence.ReasonId == 2)
{
int
_dayAb = dayAbsence.Day;
int
_dayCu = dateCurrent.Day;
if
((_dayAb - _dayCu) <= 5)
//You must register 5 days in advance.
{
//It is not allowed to create absence.
return
;
}
}
/*Id Reason Free Day = 5*/
else
if
(absence.SubReason == 5)
{
int
dayAb = dayAbsence.Day;
if
(dayAb >= 5)
//It is only allowed until the 5th of each month.
{
//It is not allowed to create absence.
return
;
}
}
/*Id Moving = 8*/
else
if
(absence.SuBReason == 8)
{
int
_dayAb = dayAbsence.Day;
int
_dayCu = dateCurrent.Day;
if
((_dayAb - _dayCu) <= 2)
//You must register 3 days in advance.
{
//It is not allowed to create absence.
return
;
}
}
//it is allowed to create the absence
}
I want to know how I can improve this code when new requirements appear.
What do you recommend me?
I'm looking at a bit of SOLID principles but still don't figure out how to fix this.
Sorry if I extended myself too long.
Thanks,
Reply
Answers (
3
)
How to save values from modal popup to html table
Display value from database in textbox using c# oop