public JsonResult ApproveUpdateTimesheetEntry(TimesheetEntryDTO model) { //If updating then Finish day should be set if it is not alread if (!model.FinishDay.HasValue) { model.FinishDay = model.StartDay; } using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { var responseMessage = httpClient.PostAsJsonAsync("/api/TimesheetAPI/ApproveUpdateTimesheetEntry", model).Result; if (responseMessage.IsSuccessStatusCode) { // model.TimeCard. //TODO if getting next unnapproved add call to new API service to find next unnapproved var timesheetWeekDTO = GetTimesheetData(model.TimesheetId); var nextTimesheetEntry = timesheetWeekDTO.TimesheetEntries.Where(s => s.StartDateTime >= model.StartDateTime && !s.Approved).OrderBy(s => s.StartDateTime).ToList().FirstOrDefault(); //TODO NEED to be able to reload the Timsheet with ID return(Json(new { success = "true", message = "Thanks", nextId = (nextTimesheetEntry != null)?nextTimesheetEntry.Id.ToString(): "" })); } else { //If and error occurred add details to model error. var error = JsonConvert.DeserializeObject <System.Web.Http.HttpError>(responseMessage.Content.ReadAsStringAsync().Result); return(Json(new { success = "false", message = error.Message })); // do a concatenation of the model state errors } } }
public HttpResponseMessage ApproveTimesheetEntry([FromBody] TimesheetEntryDTO timesheetEntryDTO) { if (Is <TimesheetFeature> .Enabled) { TimesheetEntry timesheetEntry = db.TimesheetEntries.Find(timesheetEntryDTO.Id); if (timesheetEntry == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var email = HttpContext.Current.User.Identity.Name; UserProfile userProfile = db.UserProfiles.FirstOrDefault(usr => usr.Email == email); if (userProfile == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } //Check business rules if (!timesheetEntryDTO.FinishDateTime.HasValue) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Finish time for shift must be specified")); } if (timesheetEntryDTO.FinishDateTime.Value < timesheetEntryDTO.StartDateTime) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Finish time for shift must be AFTER start time")); } if (ClaimsAuthorization.CheckAccess("Put", "BusinessId", timesheetEntry.TimeCard.BusinessLocation.Business.Id.ToString())) { timesheetEntry.Approved = true; timesheetEntry.ApprovedDateTime = WebUI.Common.Common.DateTimeNowLocal(); timesheetEntry.ApprovedBy = userProfile; timesheetEntry.StartDateTime = timesheetEntryDTO.StartDateTime; timesheetEntry.FinishDateTime = timesheetEntryDTO.FinishDateTime; try { db.Entry(timesheetEntry).State = EntityState.Modified; db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized)); } } else { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotImplemented)); } }
public ActionResult EditTimesheetEntry(Guid id) { TimesheetEntryDTO val = null; using (HttpClientWrapper httpClient = new HttpClientWrapper(Session)) { Task <String> response = httpClient.GetStringAsync("api/TimesheetAPI/TimesheetEntry/" + id.ToString()); val = Task.Factory.StartNew(() => JsonConvert.DeserializeObject <TimesheetEntryDTO>(response.Result)).Result; } return(PartialView("_TimesheetEntryEditPartial", val)); }