private void CreateObjet() { decimal planID = 0; string strStartDate = ""; string strEndDate = ""; if (string.IsNullOrEmpty(txtStartDate.Text.Trim()) == false) { strStartDate = Common.ReturnDate(txtStartDate.Text.Trim()); } if (string.IsNullOrEmpty(txtEndDate.Text.Trim()) == false) { strEndDate = Common.ReturnDate(txtEndDate.Text.Trim()); } if (hfIsUpdate.Value == "N") { planID = 0; } else { planID = Convert.ToDecimal(hfID.Value.ToString()); } objLeavePlan = new LeavePlanDTO(); objLeavePlan.ID = planID; objLeavePlan.EmpId = txtEmpId.Text.Trim(); objLeavePlan.LTypeId = Convert.ToDecimal(ddlLeaveType.SelectedValue); objLeavePlan.StartDate = Convert.ToDateTime(strStartDate); objLeavePlan.EndDate = Convert.ToDateTime(strEndDate); objLeavePlan.Remarks = txtRemarks.Text; objLeavePlan.IsActive = ChkIsActive.Checked ? "N" : "Y"; }
public int AddLeavePlan(LeavePlanDTO objLeavePlan) { try { // insert plan if (objLeavePlan.ID == 0) { decimal maxId = context.LeavePlans.Select(mm => mm.ID).DefaultIfEmpty(0).Max(); objLeavePlan.ID = ++maxId; LeavePlan target = new LeavePlan(); objLeavePlan.Mapper(target); context.LeavePlans.Add(target); } else { // update plan LeavePlan exPlan = context.LeavePlans.Where(ll => ll.ID == objLeavePlan.ID).FirstOrDefault(); exPlan.EmpId = objLeavePlan.EmpId; exPlan.LTypeId = objLeavePlan.LTypeId; exPlan.StartDate = objLeavePlan.StartDate; exPlan.EndDate = objLeavePlan.EndDate; exPlan.Remarks = objLeavePlan.Remarks; exPlan.IsActive = objLeavePlan.IsActive; } int cnt = context.SaveChanges(); return(cnt); } catch (Exception exc) { return(0); } }