public async Task <IActionResult> Create([Bind("id,startDate,endDate,appicationDate,approved")] HospitalLeaveModel HospitalLeaveModel, IFormFile abCard) { if (await extractUser()) { ModelState.Remove("applicant"); ModelState.Remove("ambulatoryCard"); if (ModelState.IsValid && HospitalLeaveModel.startDate >= DateTime.Now && HospitalLeaveModel.startDate <= HospitalLeaveModel.endDate && abCard != null) { using (var ms = new MemoryStream()) { abCard.CopyTo(ms); HospitalLeaveModel.ambulatoryCard = ms.ToArray(); } HospitalLeaveModel.applicant = user; _context.Add(HospitalLeaveModel); await _context.SaveChangesAsync(); return(RedirectToAction("IndexDisapproved")); } return(View("~/Views/Holidays/HolidaysHospitalCRUD/Create.cshtml", HospitalLeaveModel)); } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Approve(int?id) { if (await extractUser()) { HospitalLeaveModel application = await _context.HospitalLeaves.FindAsync(id); user = await _context.Users.Include(u => u.leadedTeam).ThenInclude(u => u.devs).FirstOrDefaultAsync(u => u.id == user.id); if (user.role.name == "CEO" || (user.role.name == "Team Lead" && user.leadedTeam.devs.Any(d => d.hospitalLeaves.Contains(application)))) { application.approved = true; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(IndexDisapproved))); } else { return(View("NoPermission")); } } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Edit(int id, [Bind("id,isPaid,startDate,endDate,appicationDate,halfDay")] HospitalLeaveModel HospitalLeaveModel, IFormFile abCard) { if (await extractUser()) { if (id != HospitalLeaveModel.id) { return(NotFound()); } ModelState.Remove("ambulatoryCard"); ModelState.Remove("applicant"); if (ModelState.IsValid) { if (HospitalLeaveModel.approved == false) { try { HospitalLeaveModel UpdatedModel = await _context.HospitalLeaves.FindAsync(id); UpdatedModel.startDate = HospitalLeaveModel.startDate; UpdatedModel.applicant = user; if (abCard != null) { using (var ms = new MemoryStream()) { abCard.CopyTo(ms); UpdatedModel.ambulatoryCard = ms.ToArray(); } } await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HospitalLeaveModelExists(HospitalLeaveModel.id)) { return(NotFound()); } else { throw; } } //TODO: da vrushta dr action i viewdata return(RedirectToAction(nameof(IndexDisapproved))); } else { return(View("NoPermission")); } } return(View("~/Views/Holidays/HolidaysHospitalCRUD/Edit.cshtml", HospitalLeaveModel)); } else { return(RedirectToAction("Index", "LogIn")); } }