public RedirectToActionResult Approve(AbsenceRequest model) { //First get the current Absence Request AbsenceRequest absenceRequest = data.AbsenceRequests.Get( new QueryOptions <AbsenceRequest> { Where = ar => ar.AbsenceRequestId == model.AbsenceRequestId, Include = "AbsenceStatus, User, AbsenceRequestPeriods, AbsenceRequestPeriods.Period" }); //Update absence with new changes. absenceRequest.AbsenceStatus = data.AbsenceStatusTypes.List().Where(st => st.Name == "Approved").FirstOrDefault(); absenceRequest.DateProcessed = DateTime.Now; absenceRequest.StatusRemarks = model.StatusRemarks; data.AbsenceRequests.Update(absenceRequest); //Save all changes data.Save(); TempData["SucessMessage"] = "The Absence Request with ID#, " + absenceRequest.AbsenceRequestId + ", was approved sucessfully."; //To retain grid state, send the current grid values to the List View. var gridBuilder = new AbsenceGridBuilder(HttpContext.Session); return(RedirectToAction("List", gridBuilder.CurrentGrid)); }
public IActionResult Deny(AbsenceRequest model) { //To retain grid state, send the current grid values to the List View. var gridBuilder = new AbsenceGridBuilder(HttpContext.Session); //First get the current Absence Request AbsenceRequest absenceRequest = data.AbsenceRequests.Get( new QueryOptions <AbsenceRequest> { Where = ar => ar.AbsenceRequestId == model.AbsenceRequestId, Include = "AbsenceStatus, User, AbsenceRequestPeriods, AbsenceRequestPeriods.Period" }); if (model.StatusRemarks == null) { TempData["FailureMessage"] = "Unable to Deny the Absence Request for " + absenceRequest.User.FullName + ". If absence is denied, need to provide a reason in status remarks."; return(RedirectToAction("List", gridBuilder.CurrentGrid)); } else { //Update absence with new status of "Denied" absenceRequest.AbsenceStatus = data.AbsenceStatusTypes.List().Where(st => st.Name == "Denied").FirstOrDefault(); absenceRequest.DateProcessed = DateTime.Now; absenceRequest.StatusRemarks = model.StatusRemarks; data.AbsenceRequests.Update(absenceRequest); //Save all changes data.Save(); TempData["SucessMessage"] = "The Absence Request with ID#, " + absenceRequest.AbsenceRequestId + ", was denied sucessfully."; return(RedirectToAction("List", gridBuilder.CurrentGrid)); } }
public IActionResult AddSubJob(string id, bool list = false) { //First get the Absence Request AbsenceRequest absenceRequest = data.AbsenceRequests.Get(new QueryOptions <AbsenceRequest> { Include = "DurationType, AbsenceRequestPeriods, User, SubJob, SubJob.User, SubJob.SubJobStatus", Where = ar => ar.AbsenceRequestId == id, }); //Then copy the absence values to the new sub job. SubJob subJob = new SubJob { StartDate = absenceRequest.StartDate, EndDate = absenceRequest.EndDate, StartTime = absenceRequest.StartTime, EndTime = absenceRequest.EndTime, DurationTypeId = absenceRequest.DurationTypeId, SubJobStatus = data.SubJobStatuses.List().Where(ct => ct.Name == "Unfilled").FirstOrDefault(), AbsenceRequest = absenceRequest }; data.SubJobs.Insert(subJob); data.Save(); if (list) { return(RedirectToAction("List")); } else { return(RedirectToAction("Details", new { ID = absenceRequest.AbsenceRequestId })); } }
private SlippingRequest GetSlippingRequest(AbsenceRequest absenceRequest, ICollection <AbsenceRequestOppositionMP> absenceRequestOppositionMPs) { SlippingRequest slippingRequest = new SlippingRequest() { ID = absenceRequest.ID, MPID = absenceRequest.MPID, ReasonID = absenceRequest.ReasonID, Reason = absenceRequest.ReasonID.HasValue ? absenceRequest.AbsenceRequestReason.Reason : string.Empty, Details = absenceRequest.Details, StatusID = absenceRequest.StatusID, Status = absenceRequest.AbsenceRequestStatus.Status, FromDate = absenceRequest.FromDate.ToUkTimeFromUtc(), ToDate = absenceRequest.ToDate.HasValue ? ((DateTime)absenceRequest.ToDate).ToUkTimeFromUtc() : absenceRequest.ToDate, DecisionNotes = absenceRequest.DecisionNotes, CreatedBy = (int)absenceRequest.CreatedBy, LastChangedBy = absenceRequest.LastChangedBy, Location = absenceRequest.Location, TravelTimeInHours = absenceRequest.TravelTimeInHours, OppositionMPsAttending = absenceRequest.OppositionMPsAttending, OppositionMPs = absenceRequestOppositionMPs.Count > 0 ? absenceRequestOppositionMPs.Select(a => new OppositionMP { ID = a.ID, MPID = a.MPID, FullName = a.MPFullName }).ToList() : new List <OppositionMP>() }; return(slippingRequest); }
private AbsenceRequest GetAbsenceRequest(SlippingRequest slippingRequest, int MPID, int userId) { AbsenceRequest absenceRequest; if (slippingRequest.ID == 0) { absenceRequest = new AbsenceRequest() { CreatedBy = userId, CreatedDate = DateTime.UtcNow, MPID = MPID }; } else { absenceRequest = db.AbsenceRequests.Find(slippingRequest.ID); } if (absenceRequest != null) { absenceRequest.LastChangedBy = userId; absenceRequest.LastChangedDate = DateTime.UtcNow; absenceRequest.ReasonID = slippingRequest.ReasonID; absenceRequest.Details = slippingRequest.Details; absenceRequest.StatusID = slippingRequest.StatusID; absenceRequest.FromDate = slippingRequest.FromDate.ToUtcFromUkTime(); absenceRequest.ToDate = slippingRequest.ToDate.HasValue ? ((DateTime)slippingRequest.ToDate).ToUtcFromUkTime() : slippingRequest.ToDate; absenceRequest.DecisionNotes = slippingRequest.DecisionNotes; absenceRequest.Location = slippingRequest.Location; absenceRequest.TravelTimeInHours = slippingRequest.TravelTimeInHours; absenceRequest.OppositionMPsAttending = slippingRequest.OppositionMPsAttending; } return(absenceRequest); }
private AbsenceRequest GetAbsenceRequest(string id) { AbsenceRequest absenceRequest = data.AbsenceRequests.Get(new QueryOptions <AbsenceRequest> { Where = ar => ar.AbsenceRequestId == id, Include = "AbsenceType, DurationType, AbsenceStatus, User, AbsenceRequestPeriods", }); return(absenceRequest); }
public string GetPeriodsNeedCoverage(AbsenceRequest ar) { string periods = ""; foreach (AbsenceRequestPeriod period in ar.AbsenceRequestPeriods.OrderBy(arp => arp.PeriodId).ToList()) { periods += period.PeriodId + " "; } return(periods); }
public static ScheduleCreatedEvent FromAbsenceRequest(AbsenceRequest request) { var evt = new ScheduleCreatedEvent( request.Id, request.RequestedBy, request.NeedsApproval, request.StartDate, request.EndDate); return(evt); }
internal bool Exists(int requestId, int userId) { AbsenceRequest absenceRequest = db.AbsenceRequests.Find(requestId); if (absenceRequest != null) { return(UserCanActForMP(userId, absenceRequest.MPID)); } else { return(false); } }
public void DeleteAbsenceRequestPeriods(AbsenceRequest absenceRequest) { //Get the current AbsenceRequestPeriods for this absenceRequest var currentPeriods = AbsenceRequestPeriods.List(new QueryOptions <AbsenceRequestPeriod> { Where = arp => arp.AbsenceRequestId == absenceRequest.AbsenceRequestId }); //Delete all of the records aquired above. foreach (AbsenceRequestPeriod arp in currentPeriods) { AbsenceRequestPeriods.Delete(arp); } }
public int CreateOrUpdate(SlippingRequest slippingRequest, int MPID, int userId) { AbsenceRequest absenceRequest = GetAbsenceRequest(slippingRequest, MPID, userId); if (absenceRequest.ID == 0) { db.AbsenceRequests.Add(absenceRequest); } else { db.Entry(absenceRequest).State = EntityState.Modified; } if (absenceRequest.OppositionMPsAttending == true) { var removedMPs = new List <AbsenceRequestOppositionMP>(); foreach (var mp in absenceRequest.AbsenceRequestOppositionMPs) { if (!slippingRequest.OppositionMPs.Select(m => m.ID).Contains(mp.ID)) { removedMPs.Add(mp); } } db.AbsenceRequestOppositionMPs.RemoveRange(removedMPs); foreach (var mp in slippingRequest.OppositionMPs) { var absenceRequestOppositionMP = GetAbsenceRequestOppositionMP(mp, absenceRequest.ID, userId); if (absenceRequestOppositionMP.ID == 0) { db.AbsenceRequestOppositionMPs.Add(absenceRequestOppositionMP); } else { db.Entry(absenceRequestOppositionMP).State = EntityState.Modified; } } } else { foreach (var mp in db.AbsenceRequestOppositionMPs.Where(m => m.AbsenceRequestID == absenceRequest.ID)) { db.AbsenceRequestOppositionMPs.Remove(mp); } } db.SaveChanges(); return(absenceRequest.ID); }
public SlippingRequest Get(int requestId, int userId) { if (Exists(requestId, userId)) { AbsenceRequest absenceRequest = db.AbsenceRequests.Find(requestId); var absenceRequestOppositionMPs = absenceRequest.AbsenceRequestOppositionMPs; SlippingRequest slippingRequest = GetSlippingRequest(absenceRequest, absenceRequestOppositionMPs); return(slippingRequest); } else { return(null); } }
public void AddNewAbsenceRequestPeriods(AbsenceRequest absenceRequest, List <SelectablePeriodViewModel> selectablePeriods) { //Add the AbsenceRequestPeriods foreach (SelectablePeriodViewModel p in selectablePeriods) { if (p.Checked == true) { AbsenceRequestPeriod arp = new AbsenceRequestPeriod { AbsenceRequest = absenceRequest, PeriodId = p.PeriodId }; AbsenceRequestPeriods.Insert(arp); } } }
public IActionResult Edit(string id) { AbsenceRequest absenceReqest = GetAbsenceRequest(id); AbsenceViewModel model = new AbsenceViewModel { AbsenceRequest = absenceReqest, NeedCoverageInput = absenceReqest.NeedCoverage == true ? "true" : "false", AbsenceTypes = data.AbsenceTypes.List(), DurationTypes = data.DurationTypes.List(), SelectablePeriods = new List <SelectablePeriodViewModel>() }; //Populate Period Check List model.SelectablePeriods = PopulateSelectablePeriodCheckList(model.SelectablePeriods); //Show Check marks on Periods Need Coverage. foreach (AbsenceRequestPeriod p in absenceReqest.AbsenceRequestPeriods) { model.SelectablePeriods[p.Period.PeriodNumber - 1].Checked = true; } return(View("Absence", model)); }
public async Task <IActionResult> GetAbsenceRequest([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } AbsenceRequest absenceRequest = await _repo.Find(id); if (absenceRequest == null) { return(NotFound()); } // users cannot see others requests except admins if (!User.IsInRole(SeedData.AdminRole) && absenceRequest.UserId != GetCurrentUserId()) { return(NotFound()); } return(Ok(_mapper.Map <AbsenceRequestDto>(absenceRequest))); }
public RedirectToActionResult Cancel(AbsenceRequest model) { //First get the current Absence Request AbsenceRequest absenceRequest = data.AbsenceRequests.Get( new QueryOptions <AbsenceRequest> { Where = ar => ar.AbsenceRequestId == model.AbsenceRequestId, Include = "AbsenceStatus, User, AbsenceRequestPeriods, AbsenceRequestPeriods.Period, SubJob" }); if (absenceRequest.NeedCoverage == false) { data.AbsenceRequests.Delete(absenceRequest); } else { if (absenceRequest.SubJob == null) { data.AbsenceRequests.Delete(absenceRequest); } else { data.SubJobs.Delete(absenceRequest.SubJob); data.AbsenceRequests.Delete(absenceRequest); } } //Save all changes data.Save(); TempData["SucessMessage"] = "The Absence Request with ID#, " + absenceRequest.AbsenceRequestId + ", was canceled sucessfully."; //To retain grid state, send the current grid values to the List View. var gridBuilder = new AbsenceGridBuilder(HttpContext.Session); return(RedirectToAction("List", gridBuilder.CurrentGrid)); }
public IActionResult DeleteSubJob(string id, bool list = false) { //First get the Absence Request AbsenceRequest absenceRequest = data.AbsenceRequests.Get(new QueryOptions <AbsenceRequest> { Include = "DurationType, AbsenceRequestPeriods, User, SubJob, SubJob.User, SubJob.SubJobStatus", Where = ar => ar.AbsenceRequestId == id, }); data.SubJobs.Delete(absenceRequest.SubJob); data.Save(); if (list) { return(RedirectToAction("List")); } else { return(RedirectToAction("Details", new { ID = absenceRequest.AbsenceRequestId })); } }
public async Task <IActionResult> PostAbsenceRequest([FromBody] AbsenceRequestCreateDto absenceRequestCreateDto) { //todo: validation (dates not in past etc.) if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newAbsenceRequest = new AbsenceRequest() { CreatedAt = DateTime.UtcNow, FromDate = absenceRequestCreateDto.FromDate, ToDate = absenceRequestCreateDto.ToDate, State = AbsenceRequestState.Requested, UserId = GetCurrentUserId() }; _repo.Add(newAbsenceRequest); try { await _repo.Save(); } catch (DbUpdateException) { if (await AbsenceRequestExists(newAbsenceRequest.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetAbsenceRequest", new { id = newAbsenceRequest.Id }, _mapper.Map <AbsenceRequestDto>(newAbsenceRequest))); }
public IActionResult CreateAbsence([FromBody] AbsenceRequest request) { var userId = GetUserId(); var existing = _timesheetRepository.GetTimesheet(userId, request.Date.Date); if (existing != null) { return(BadRequest()); } var absence = new Timesheet { UserId = userId, Date = request.Date.Date, Comment = request.Comment, Absence = true }; _timesheetRepository.CreateTimesheet(absence); var result = _mapper.Map <TimesheetResponse>(absence); return(Ok(result)); }
public bool Update(AbsenceRequest entity) { _db.AbsenceRequests.Update(entity); return(Save()); }
public bool Create(AbsenceRequest entity) { _db.AbsenceRequests.Add(entity); return(Save()); }
public bool Delete(AbsenceRequest entity) { _db.AbsenceRequests.Remove(entity); return(Save()); }