public async Task <bool> UpdateBPFCHistory(BPFCHistory entity) { var item = await _repoBPFCHistory.FindAll().FirstOrDefaultAsync(x => x.ID == entity.ID); item.Remark = entity.Remark; return(await _repoBPFCHistory.SaveAll()); }
public async Task <bool> Create(BPFCHistoryDto entity) { var entitys = new BPFCHistory(); if (!await _repoBPFCHistory.CheckGlueID(entity.GlueID)) { var checkBPFC = _repoBPFCEstablish.FindById(entity.BPFCEstablishID); if (checkBPFC.FinishedStatus == true && checkBPFC.ApprovalStatus == true) { if (entity.Action == "Consumption") { entitys.Action = "Improve"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else if (entity.Action == "Delete") { entitys.Action = "Delete"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else { entitys.Action = "Improve"; entitys.Before = entity.BeforeAllow; entitys.After = entity.AfterAllow; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } checkBPFC.ApprovalStatus = false; checkBPFC.FinishedStatus = false; await _repoBPFCEstablish.SaveAll(); } else if (checkBPFC.FinishedStatus == true && checkBPFC.ApprovalStatus == false) { if (entity.Action == "Consumption") { entitys.Action = "Modified"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else if (entity.Action == "Delete") { entitys.Action = "Delete"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else { entitys.Action = "Modified"; entitys.Before = entity.BeforeAllow; entitys.After = entity.AfterAllow; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } } else { if (entity.Action == "Consumption") { entitys.Action = "Update"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else if (entity.Action == "Delete") { entitys.Action = "Delete"; entitys.Before = entity.Before; entitys.After = entity.After; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } else { entitys.Action = "Update"; entitys.Before = entity.BeforeAllow; entitys.After = entity.AfterAllow; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } } } else { if (entity.Action == "Created") { entitys.Action = entity.Action; entitys.Before = ""; entitys.After = ""; entitys.BPFCEstablishID = entity.BPFCEstablishID; entitys.UserID = entity.UserID; entitys.GlueID = entity.GlueID; } } try { _repoBPFCHistory.Add(entitys); await _repoBPFCHistory.SaveAll(); return(true); } catch { return(false); } }
public async Task <object> Reject(int bpfcID, int userid) { var item = _repoBPFCEstablish.FindById(bpfcID); try { item.FinishedStatus = false; item.ApprovalStatus = false; item.ApprovalBy = userid; //add Reject vao history var result = new BPFCHistory(); result.Action = "Rejected"; result.BPFCEstablishID = bpfcID; var remark = _repoComment.FindAll().Where(x => x.BPFCEstablishID == bpfcID).OrderBy(y => y.CreatedDate).LastOrDefault(); if (remark == null) { //rollback return(new { status = false, message = "Please Enter new comment to Reject BPFC !" }); } result.Remark = remark.Content; result.UserID = userid; var timePresent = DateTime.Now; var timeLast = Convert.ToDateTime(remark.CreatedDate); var compare = DateTime.Compare(timePresent.Date, timeLast.Date); if (compare > 0) { return(new { status = false, message = "The Lastest comment allow 1 Hour , Please Enter new comment to Reject BPFC !", userId = item.CreatedBy }); } if (compare == 0 && timePresent.TimeOfDay.TotalHours - timeLast.TimeOfDay.TotalHours > 1) { return(new { status = false, message = "The Lastest comment allow 1 Hour , Please Enter new comment to Reject BPFC !", userId = item.CreatedBy }); } _repoBPFCHistory.Add(result); var status2 = await _repoBPFCEstablish.SaveAll(); return(new { status = status2, message = "The model name has been rejected!!!", userId = item.CreatedBy }); } catch (Exception ex) { return(new { status = false, message = ex.Message }); } }
public async Task <ActionResult <BPFCHistory> > UpdateBPFCHistory(BPFCHistory entity) { return(Ok(await _bPFCEstablishService.UpdateBPFCHistory(entity))); }