c# - Updation on DB with the different categories in Asp.net MVC -
i creating project related leave absence. leave maintained & manipulated according different categories.
every flow of concept working, except calculating leave days & showing balance.
i have created model named, leavereq.cs
public class leavereq { public int id {get; set; } [display(name = "employee name")] public string emp_name { get; set; } [display(name = "requested day")] public string day_ctg { get; set; } [display(name = "start date")] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:mm-dd-yyyy}", applyformatineditmode = true)] public datetime startdt { get; set; } [display(name = "end date")] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:mm-dd-yyyy}", applyformatineditmode = true)] public datetime enddt { get; set; } [display(name = "time-off category")] public string category { get; set; } [display(name = "applied on")] [datatype(datatype.date)] [displayformat(dataformatstring = "{0:mm-dd-yyyy}", applyformatineditmode = true)] public datetime apply { get; set; } [display(name = "balance")] public string bal { get; set; } }
and screen like,
i have created model named, timeoffsettigs.cs
public class timeoffsettigs { public int id { get; set; } [display(name = "time-off type")] [stringlength(30, minimumlength = 3)] public string type { get; set; } [display(name = "time-off category")] public string category { get; set; } [display(name = "maximum allowance")] public int allowance { get; set; } }
basic concept that, when employee applies leave in category. balance leave should shown. on applying, allowance should deducted remaining balance.
for example. if applying leave in vacation & full day (8hrs). allowance vacation 80hrs. on applying leave first time. balance stored (80-8) 72hours. on applying next time half day(4hrs). balance should stored (72-4) 68hrs in db
i have written code, concept in controller.cs
[httppost, actionname("approve")] [validateantiforgerytoken] public actionresult lvdetailsconfirmed(int id) { leavereq levreq = dblv.leave_dts.find(id); timeoffsettigs timesettings = dbts.policy_tbl.find(id); if (levreq.bal == null) { if (levreq.day_ctg == "full day") { var bal_full = 8; levreq.bal = (timesettings.allowance - bal_full).tostring(); } else if (levreq.day_ctg == "partial day") { var bal_par = 4; levreq.bal = (timesettings.allowance - bal_par).tostring(); } else { var timespan = levreq.enddt.subtract(levreq.startdt); var dayscalc = timespan.days; var bal_mul = 8 * dayscalc; levreq.bal = (timesettings.allowance - bal_mul).tostring(); } } else { if (levreq.day_ctg == "full day") { var bal_full = 8; levreq.bal = (convert.toint32(levreq.bal) - bal_full).tostring(); } else if (levreq.day_ctg == "partial day") { var bal_par = 4; levreq.bal = (convert.toint32(levreq.bal) - bal_par).tostring(); } else { var timespan = levreq.enddt.subtract(levreq.startdt); var dayscalc = timespan.days; var bal_mul = 8 * dayscalc; levreq.bal = (convert.toint32(levreq.bal) - bal_mul).tostring(); } } if (modelstate.isvalid) { dblv.entry(levreq).state = entitystate.modified; dblv.savechanges(); return redirecttoaction("eleave"); } return view(levreq);
approval/request screen looking like,
on clicking approve, balance should deducted. on clicking reject, balance shouldnt deducted.
don't know, wrong did in controller. whenever press approve, nothing change happening in db.
this approval button code
@using (html.beginform()) { @html.antiforgerytoken() <div class="form-actions no-color"> <input type="submit" value="approve" class="btn btn-default" name="aprbtn" /> | <input type="submit" value="reject" class="btn btn-default" name="rejbtn"/> @html.actionlink("back list", "eleave") </div> }
give name button , check.
<input type="submit" value="approve" class="btn btn-default" name="approve" />
Comments
Post a Comment