public ProcessRequestDTO SaveDataToPublic(string pcr_code) { log.MethodStart(); var currentDateTime = DateTime.Now; var currentUser = ""; ProcessRequestDTO objReturn = new ProcessRequestDTO(); using (var trans = _db.Database.BeginTransaction()) { try { var objModel = new TRProcessRequest(); objModel = _db.TRProcessRequests.FirstOrDefault(x => x.pcr_code == pcr_code); if (objModel != null) { objModel.pcr_status = "P"; objModel.pcr_updateuser = currentUser; objModel.pcr_updatedate = currentDateTime; #region Save Log Process ... _db.LogProcesss.Add(new LogProcess() { log_usr_id = currentUser, log_mnu_id = "", log_mnu_name = "ProcessRequest", log_tran_id = objModel.pcr_id.ToString(), log_action = (objModel.pcr_status == "N" ? "New" : "Update"), log_desc = "Update ProcessRequest " + objModel.pcr_code, log_createuser = currentUser, log_createdate = currentDateTime }); #endregion _db.SaveChanges(); trans.Commit(); } objReturn = _mapper.Map <ProcessRequestDTO>(objModel); } catch (Exception ex) { // TODO: Handle failure trans.Rollback(); } finally { trans.Dispose(); } } log.MethodFinish(); return(objReturn); }
public ProcessRequestDTO SaveData(ProcessRequestDTO model) { log.MethodStart(); var currentDateTime = DateTime.Now; var currentUser = ""; var new_pcr_code = ""; ProcessRequestDTO objReturn = new ProcessRequestDTO(); using (var trans = _db.Database.BeginTransaction()) { try { var objModel = new TRProcessRequest(); objModel = _mapper.Map <TRProcessRequest>(model); var currentYearCode = $"PCR_{DateTime.Now.ToString("yyyyMMdd")}"; var objDataList = _db.TRProcessRequests.Where(x => x.pcr_code.Contains(currentYearCode)).ToList(); if (objDataList.Count > 0) { var lastData = objDataList.LastOrDefault(); var lastCode = lastData.pcr_code.Replace(currentYearCode, ""); var newCodeInt = (Convert.ToInt32(lastCode) + 1); new_pcr_code = currentYearCode + newCodeInt.ToString("0000"); } else { new_pcr_code = currentYearCode + (1).ToString("0000"); } objModel.pcr_id = 0; objModel.pcr_code = new_pcr_code; objModel.pcr_status = "W"; objModel.pcr_active = true; objModel.pcr_status = objModel.pcr_active == true ? "A" : "I"; objModel.pcr_createdate = currentDateTime; objModel.pcr_updatedate = currentDateTime; currentUser = objModel.pcr_updateuser; _db.TRProcessRequests.Add(objModel); var objData = _db.TRProcessRequests.FirstOrDefault(x => x.pcr_code == model.pcr_prev_code); if (objData != null) { objData.pcr_status = "I"; objData.pcr_active = false; objData.pcr_updateuser = model.pcr_updateuser; objData.pcr_updatedate = currentDateTime; } #region Save Log Process ... _db.LogProcesss.Add(new LogProcess() { log_usr_id = currentUser, log_mnu_id = "", log_mnu_name = "ProcessRequest", log_tran_id = objModel.pcr_id.ToString(), log_action = (model.pcr_status == "N" ? "New" : "Update"), log_desc = "Update ProcessRequest " + objModel.pcr_code, log_createuser = currentUser, log_createdate = currentDateTime }); #endregion _db.SaveChanges(); trans.Commit(); objReturn = _mapper.Map <ProcessRequestDTO>(objModel); } catch (Exception ex) { // TODO: Handle failure trans.Rollback(); } finally { trans.Dispose(); } } log.MethodFinish(); return(objReturn); }