我正在创建一个与Leave Absence相关的项目。离开将保持&根据不同的类别进行操纵。
每一个概念流都在运作,除了计算离开日和时间。显示平衡。
我创建了一个名为Model的模型, 的 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; }
}
和屏幕想要,
我创建了一个名为Model 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; }
}
基本概念是,当员工在一个类别中申请离职时。应该展示他的平衡假。申请时,应从余额中扣除某些津贴。
例如。如果我在Vacation& amp;全天(8小时)。 度假津贴是80小时。 关于申请首次休假。我的余额存储为(80-8)72小时。 下次申请半天(4小时)。我的余额应存储为数据库中的(72-4)68小时
我已在 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);
批准/请求屏幕看起来像,
单击“批准”时,应该扣除余额。 在单击拒绝时,不应扣除余额。
不知道,我在控制器中做了什么错。每当我按下批准时,数据库中都没有发生任何变化。
这是批准按钮代码
@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 to List", "ELeave")
</div>
}
答案 0 :(得分:0)
给按钮命名,然后检查。
<input type="submit" value="Approve" class="btn btn-default" name="Approve" />