public int SaveRemarks(MaintenanceGridModel MR)// MR { Data.Models.MaintenanceRequest oldMR = _MRepository.Table.FirstOrDefault(w => w.Id == MR.Id); if (oldMR != null) { if (MR.StatusId == 1) { oldMR.PriorityId = MR.PriorityId; oldMR.StatusId = 2; oldMR.Problem = MR.Problem; oldMR.Description = MR.Description; oldMR.AssignTo = MR.AssignTo; oldMR.AssignBy = MR.AssignBy; oldMR.AssignDate = DateTime.Now; oldMR.Remarks = MR.Remarks; oldMR.RemarksBy = MR.RemarksBy; oldMR.BreakdownType = MR.BreakdownType; oldMR.RemarksDate = DateTime.Now; } else if (MR.StatusId == 2) //Progress { oldMR.StatusId = 3; oldMR.ProgressBy = MR.ProgressBy; oldMR.ProgressDate = DateTime.Now; oldMR.ProgressRemarks = MR.ProgressRemarks; oldMR.WorkStartDate = MR.WorkStartDate; oldMR.WorkStartTime = MR.WorkStartTime.Value.TimeOfDay; } else if (MR.StatusId == 3)//Complete { oldMR.StatusId = 4; oldMR.WorkEndDate = MR.WorkEndDate; oldMR.WorkEndTime = MR.WorkEndTime.Value.TimeOfDay; oldMR.CompleteBy = MR.CompleteBy; oldMR.CompleteDate = DateTime.Now; oldMR.CompleteRemarks = MR.CompleteRemarks; } else if (MR.StatusId == 4)//close { oldMR.StatusId = 5; oldMR.CloseDate = DateTime.Now; oldMR.CloseBy = MR.CloseBy; oldMR.CloseRemarks = MR.CloseRemarks; TimeSpan rtime = oldMR.RequestTime; DateTime requestDate = oldMR.RequestDate + rtime; var totaltime = (oldMR.WorkEndTime - rtime).Value.TotalMilliseconds; DateTime?endDate = oldMR.WorkEndDate + oldMR.WorkEndTime; var day = oldMR.WorkEndDate - oldMR.RequestDate; if (oldMR.IsBreakdown == true) { //if(oldMR.WorkEndDate > oldMR.RequestDate) //{ var endTime = new TimeSpan(23, 59, 59); totaltime = (endTime - rtime).TotalMilliseconds; for (int i = 0; i <= day.Value.Days; i++) { this._breakdownRepository.Insert(new Data.Models.BreakDown { PlantId = oldMR.PlantId ?? default(int), LineId = oldMR.LineId ?? default(int), MachineId = oldMR.MachineId ?? default(int), Date = requestDate, StartTime = rtime, //EndTime = oldMR.WorkEndTime ?? default(TimeSpan), EndTime = day.Value.Days == 0 ? oldMR.WorkEndTime ?? default(TimeSpan) : endTime, //TotalTime = unchecked((int)totaltime), TotalTime = day.Value.Days == 0 ? unchecked ((int)(oldMR.WorkEndTime - rtime).Value.TotalMilliseconds) : unchecked ((int)totaltime), ElectricalTime = oldMR.BreakdownType == 1 ? true : false, MechTime = oldMR.BreakdownType == 2 ? true : false, InstrTime = oldMR.BreakdownType == 3 ? true : false, FailureDescription = oldMR.Description, CreatedBy = oldMR.CreatedBy, CreatedDate = oldMR.CreatedDate, }); requestDate = requestDate.AddDays(1); if (i == (day.Value.Days - 1)) { rtime = new TimeSpan(00, 00, 00); endTime = oldMR.WorkEndTime ?? default(TimeSpan); totaltime = (endTime - rtime).TotalMilliseconds; } else { rtime = new TimeSpan(00, 00, 00); endTime = new TimeSpan(23, 59, 59); totaltime = (endTime - rtime).TotalMilliseconds; } } } } _MRepository.Update(oldMR); return(oldMR.Id); } else { return(0); } }
public JsonNetResult SaveRemarks(MaintenanceGridModel MaintenanceRequest)//MaintenanceRequest MaintenanceRequest { var result = new JsonResponse(); try { if (MaintenanceRequest.Id != 0) { var existing = this._mrServices.GetForId(MaintenanceRequest.Id); TimeSpan?starttime = existing.WorkStartTime; TimeSpan requesttime = existing.RequestTime; DateTime?sDate = existing.WorkStartDate;//+ starttime; DateTime?sTime = existing.WorkStartDate + starttime; DateTime rDate = existing.RequestDate; DateTime rTime = existing.RequestDate + requesttime; if (MaintenanceRequest.StatusId == 1) { MaintenanceRequest.AssignBy = HttpContext.User.Identity.GetUserId <int>(); MaintenanceRequest.RemarksBy = HttpContext.User.Identity.GetUserId <int>(); this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else if (MaintenanceRequest.StatusId == 2) { MaintenanceRequest.ProgressBy = HttpContext.User.Identity.GetUserId <int>(); if (MaintenanceRequest.WorkStartDate <= rDate)//end date is less { result.Status = JsonResponseStatus.Warning; result.Message = "Start date is less then working request date"; } else if (MaintenanceRequest.WorkStartDate.Value.Date > rDate) //next day start time { this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else if (MaintenanceRequest.WorkStartTime.Value.TimeOfDay > requesttime) //start time is greater { this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else { result.Status = JsonResponseStatus.Warning; result.Message = "Start time is less then working request time"; } } else if (MaintenanceRequest.StatusId == 3) { MaintenanceRequest.CompleteBy = HttpContext.User.Identity.GetUserId <int>(); if (MaintenanceRequest.WorkEndDate <= sDate) //end date is less { result.Status = JsonResponseStatus.Warning; result.Message = "Working end date is less then working start date"; } else if (MaintenanceRequest.WorkEndDate.Value.Date > sDate) //next day start time { this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else if (MaintenanceRequest.WorkEndTime.Value.TimeOfDay > starttime) //end time is greater { this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else { result.Status = JsonResponseStatus.Warning; result.Message = "Working end date is less then working start date"; } } else if (MaintenanceRequest.StatusId == 4) { MaintenanceRequest.CloseBy = HttpContext.User.Identity.GetUserId <int>(); this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } else { this._mrServices.SaveRemarks(MaintenanceRequest); result.Status = JsonResponseStatus.Success; result.Message = "Maintenance request updated"; } } return(JsonNet(result, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { result.Status = JsonResponseStatus.Error; result.Message = ProcessException(ex); return(JsonNet(result, JsonRequestBehavior.AllowGet)); } }