public async Task <IActionResult> SetComplate(AllWorkPermitViewModel record) { var Message = "Data not been found."; try { var Result = false; if (record != null) { switch (record.GroupWPName) { case "CONFINED SPACE WORK PERMIT": Result = await this.ConfinedSpaceWorkPermitUpdate(record.WorkPermitId, record, record.IsCancel ?? false); break; case "LIFTING EQUIPMENT WORK PERMIT": Result = await this.LiftingWorkPermitUpdate(record.WorkPermitId, record, record.IsCancel ?? false); break; } } return(new JsonResult(new { Result }, this.DefaultJsonSettings)); } catch (Exception ex) { Message = $"Has error {ex.ToString()}"; } return(BadRequest(new { Error = Message })); }
public async Task <bool> ConfinedSpaceWorkPermitUpdate(int ConfinedSpaceId, AllWorkPermitViewModel record, bool isCancel = false) { if (ConfinedSpaceId > 0) { var isSafetyComplate = false; var HasData = await this.repositoryConfinedSpace.GetFirstOrDefaultAsync(x => x, x => x.ConfinedSpaceWorkPermitId == ConfinedSpaceId); if (isCancel) { HasData.StatusWorkPermit = StatusWorkPermit.Cancelled; } else { if (HasData.StatusWorkPermit == StatusWorkPermit.Require) { HasData.ApprovedDate = DateTime.Now; HasData.StatusWorkPermit = StatusWorkPermit.Approved; isSafetyComplate = true; } HasData.ComplateBy = record.ComplateBy; HasData.ComplateByName = record.ComplateString; HasData.ComplateDate = DateTime.Now; HasData.ComplateTimeString = DateTime.Now.ToString("HH:mm"); HasData.WorkComplate = true; HasData.AreaClear = true; HasData.KeepOutClear = true; } HasData.ModifyDate = DateTime.Now; HasData.Modifyer = record.ComplateBy; var result = await this.repositoryConfinedSpace.UpdateAsync(HasData, ConfinedSpaceId) != null; if (isCancel) { await this.SendMail(HasData.RepayMail, HasData.RequireByEmpName, "Confined Space Work Permit", false); } if (isSafetyComplate) { await this.SendMail(HasData.RepayMail, HasData.RequireByEmpName, "Confined Space Work Permit"); } return(result); } return(false); }