public static ResultResponse Approve(DesignApproveViewModel entity) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { T_Design design = db.T_Design.Where(d => d.Id == entity.Id).FirstOrDefault(); if (design != null) { design.Reject_Reason = entity.Reject_Reason; design.Assign_To = entity.Assign_To; design.Status = entity.Status; result.Message = "Data Rejected !! Transaction Design Request with code " + entity.Code + " is rejected"; if (entity.Status == 2) { design.Approved_Date = DateTime.Now; design.Approved_By = entity.Approved_By; result.Message = "Data Approved !! Transaction Design Request with code " + entity.Code + " has been updated."; } db.SaveChanges(); } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
//CREATE and EDIT public static ResultResponse Update(DesignRequestViewModel entity, List <DesignItemViewModel> entityitem) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { string newCode = GetNewCode(); T_Design design = new T_Design(); design.Code = newCode; design.Title_Header = entity.Title_Header; design.T_Event_Id = entity.T_Event_Id; design.Request_By = entity.Request_By; design.Request_Date = DateTime.Now; design.Note = entity.Note; design.Status = 1; design.Create_Date = DateTime.Now; design.Create_By = entity.Create_By; db.T_Design.Add(design); foreach (var item in entityitem) { T_Design_Item designItem = new T_Design_Item(); designItem.T_Design_Id = entity.Id; designItem.M_Product_Id = item.M_Product_Id; designItem.Title_Item = item.Title_Item; designItem.Request_Pic = item.Request_Pic; designItem.Request_Due_Date = item.Request_Due_Date; designItem.Note = item.Note; designItem.Is_Delete = item.Is_Delete; designItem.Create_By = entity.Create_By; designItem.Create_Date = DateTime.Now; db.T_Design_Item.Add(designItem); } db.SaveChanges(); result.Message = "Data Saved ! Transaction Design Request has been add with code " + entity.Code; } else { T_Design design = db.T_Design.Where(td => td.Id == entity.Id).FirstOrDefault(); if (design != null) { design.Code = entity.Code; design.T_Event_Id = entity.T_Event_Id; design.Title_Header = entity.Title_Header; design.Request_By = entity.Request_By; design.Request_Date = DateTime.Now; design.Note = entity.Note; design.Status = 1; design.Update_Date = DateTime.Now; design.Update_By = entity.Update_By; foreach (var item in entityitem) { T_Design_Item designItem = new T_Design_Item(); designItem.T_Design_Id = entity.Id; designItem.M_Product_Id = item.M_Product_Id; designItem.Title_Item = item.Title_Item; designItem.Request_Pic = item.Request_Pic; designItem.Request_Due_Date = item.Request_Due_Date; designItem.Note = item.Note; designItem.Is_Delete = item.Is_Delete; if (item.Id == 0) { designItem.Create_By = entity.Update_By; designItem.Create_Date = DateTime.Now; } else { designItem.Update_By = entity.Update_By; designItem.Update_Date = DateTime.Now; } db.T_Design_Item.Add(designItem); } db.SaveChanges(); } result.Message = "Data Update ! Transaction Design Request with code " + entity.Code + " has been update"; } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }