public IActionResult AddPolicy() { ViewBag.Persons = GetPersonsForLeavePolicy(); LeaveRules leaveRule = new LeaveRules(); return(PartialView("AddPolicy", leaveRule)); }
public IActionResult EditPolicy(int Id) { ViewBag.Locations = GetLocations(); string stringData = _services.LeaveRules.GetResponse(ApiUrl + "/api/LeavePolicy/GetPolicyById/" + Id + "").Content.ReadAsStringAsync().Result; LeaveRules leaveRule = JsonConvert.DeserializeObject <LeaveRules>(stringData); return(PartialView("EditPolicy", leaveRule)); }
public IActionResult Delete([FromRoute] int id) { LeaveRules policy = _repository.LeaveRules.FindByCondition(x => x.Id == id); List <LeaveCredit> credits = _repository.LeaveCredit.FindAllByCondition(x => x.LeaveId == id).ToList(); if (policy == null) { return(NotFound()); } policy.IsActive = false; _repository.LeaveRules.UpdateAndSave(policy); foreach (var Credit in credits) { Credit.IsActive = false; _repository.LeaveCredit.UpdateAndSave(Credit); } _repository.LeaveRules.Dispose(); return(Ok(policy)); }
public IActionResult AddPolicy(LeaveRules Leave, int[] emps) { ViewBag.Persons = GetPersonsForLeavePolicy(); ViewBag.Locations = GetLocations(); Leave.CreatedDate = DateTime.Now; Leave.UpdatedDate = DateTime.Now; if (emps.Length == 0) { ModelState.AddModelError("LocationId", "Please select at least one employee"); } if (ModelState.IsValid) { Leave.CreatedBy = Convert.ToInt32(GetSession().PersonId); Leave.IsActive = true; HttpResponseMessage response = _services.LeaveRules.PostResponse(ApiUrl + "/api/LeavePolicy/" + 0, Leave); string stringData = response.Content.ReadAsStringAsync().Result; LeaveRules LeaveRules = JsonConvert.DeserializeObject <LeaveRules>(stringData); if (response.IsSuccessStatusCode == true) { LeaveRulesWithEmp LeaveEmp = new LeaveRulesWithEmp() { Id = LeaveRules.Id, LeaveType = LeaveRules.LeaveType, Validity = LeaveRules.Validity, ValidFrom = LeaveRules.ValidFrom, ValidTo = LeaveRules.ValidTo, Employees = emps }; HttpResponseMessage response2 = _services.LeaveRulesWithEmp.PostResponse(ApiUrl + "/api/LeaveCredit/AddCredits", LeaveEmp); if (response2.IsSuccessStatusCode == true) { return(View()); } } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; } return(PartialView("AddPolicy", Leave)); }
public IActionResult EditPolicy(LeaveRules Leave) { ViewBag.Locations = GetLocations(); Leave.UpdatedDate = DateTime.Now; Leave.UpdatedBy = Convert.ToInt32(GetSession().PersonId); if (ModelState.IsValid) { Leave.IsActive = true; HttpResponseMessage response = _services.LeaveRules.PostResponse(ApiUrl + "/api/LeavePolicy/" + Leave.Id, Leave); string stringData = response.Content.ReadAsStringAsync().Result; LeaveRules LeaveRules = JsonConvert.DeserializeObject <LeaveRules>(stringData); if (response.IsSuccessStatusCode == true) { return(View()); } } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; } return(PartialView("EditPolicy", Leave)); }
public IActionResult PostLeavePolicy([FromRoute] int Id, [FromBody] LeaveRules policy) { if (Id == 0) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } policy.TenantId = TenantId; _repository.LeaveRules.CreateLeaveRuleAndSave(policy); _repository.LeaveRules.Dispose(); return(CreatedAtAction("GetLeavePolicies", new { id = policy.Id }, policy)); } else { policy.TenantId = TenantId; _repository.LeaveRules.UpdateAndSave(policy); if (policy.IsPaid == true) { List <LeaveCredit> Credits = _repository.LeaveCredit.FindAllByCondition(x => x.LeaveId == policy.Id).ToList(); foreach (var Credit in Credits) { float diff = Credit.AllotedDays - Credit.Available; Credit.LeaveType = policy.LeaveType; Credit.ValidFrom = policy.ValidFrom; Credit.ValidTo = policy.ValidTo; Credit.AllotedDays = policy.Validity; Credit.Available = Credit.AllotedDays - _repository.LeaveRules.GetLeaveCount(Credit.PersonId, Credit.LeaveId); Credit.UpdatedDate = policy.UpdatedDate; Credit.UpdatedBy = policy.UpdatedBy; _repository.LeaveCredit.UpdateAndSave(Credit); } } _repository.LeaveRules.Dispose(); return(Ok(policy)); } }