public InternalPolicyNumSetupVM GetInternalPolicyNumSetupByID(int internalPolicyNumSetupID) { try { var internalPolicyNumSetupData = unitOfWork.TblInternalPolicyNumSetupRepository.GetByID(internalPolicyNumSetupID); InternalPolicyNumSetupVM internalPolicyNumSetupVM = new InternalPolicyNumSetupVM(); internalPolicyNumSetupVM.InternalPolicyNumSetupID = internalPolicyNumSetupData.InternalPolicyNumSetupID; internalPolicyNumSetupVM.InternalPolicyNumber = internalPolicyNumSetupData.InternalPolicyNumber; internalPolicyNumSetupVM.BusinessUnitID = internalPolicyNumSetupData.BUID != null?Convert.ToInt32(internalPolicyNumSetupData.BUID) : 0; if (internalPolicyNumSetupVM.BusinessUnitID > 0) { internalPolicyNumSetupVM.BusinessUnitName = internalPolicyNumSetupData.tblBussinessUnit.BussinessUnit; } internalPolicyNumSetupVM.CreatedBy = internalPolicyNumSetupData.CreatedBy != null?Convert.ToInt32(internalPolicyNumSetupData.CreatedBy) : 0; internalPolicyNumSetupVM.CreatedDate = internalPolicyNumSetupData.CreatedDate != null?internalPolicyNumSetupData.CreatedDate.ToString() : string.Empty; internalPolicyNumSetupVM.ModifiedBy = internalPolicyNumSetupData.ModifiedBy != null?Convert.ToInt32(internalPolicyNumSetupData.ModifiedBy) : 0; internalPolicyNumSetupVM.ModifiedDate = internalPolicyNumSetupData.ModifiedDate != null?internalPolicyNumSetupData.ModifiedDate.ToString() : string.Empty; return(internalPolicyNumSetupVM); } catch (Exception ex) { throw; } }
public bool UpdateInternalPolicyNumSetup(InternalPolicyNumSetupVM internalPolicyNumSetupVM) { using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction()) { try { tblInternalPolicyNumSetup internalPolicyNumSetup = unitOfWork.TblInternalPolicyNumSetupRepository.GetByID(internalPolicyNumSetupVM.InternalPolicyNumSetupID); internalPolicyNumSetup.InternalPolicyNumber = internalPolicyNumSetupVM.InternalPolicyNumber; internalPolicyNumSetup.BUID = internalPolicyNumSetupVM.BusinessUnitID; internalPolicyNumSetup.ModifiedDate = DateTime.Now; internalPolicyNumSetup.ModifiedBy = internalPolicyNumSetupVM.ModifiedBy; unitOfWork.TblInternalPolicyNumSetupRepository.Update(internalPolicyNumSetup); unitOfWork.Save(); //Complete the Transaction dbTransaction.Commit(); return(true); } catch (Exception ex) { //Roll back the Transaction dbTransaction.Rollback(); return(false); } } }
public List <InternalPolicyNumSetupVM> GetAllInternalPolicyNumSetups() { try { var internalPolicyNumSetupData = unitOfWork.TblInternalPolicyNumSetupRepository.Get().ToList(); List <InternalPolicyNumSetupVM> internalPolicyNumSetupList = new List <InternalPolicyNumSetupVM>(); foreach (var internalPolicyNumSetup in internalPolicyNumSetupData) { InternalPolicyNumSetupVM internalPolicyNumSetupVM = new InternalPolicyNumSetupVM(); internalPolicyNumSetupVM.InternalPolicyNumSetupID = internalPolicyNumSetup.InternalPolicyNumSetupID; internalPolicyNumSetupVM.InternalPolicyNumber = internalPolicyNumSetup.InternalPolicyNumber; internalPolicyNumSetupVM.BusinessUnitID = internalPolicyNumSetup.BUID != null?Convert.ToInt32(internalPolicyNumSetup.BUID) : 0; if (internalPolicyNumSetupVM.BusinessUnitID > 0) { internalPolicyNumSetupVM.BusinessUnitName = internalPolicyNumSetup.tblBussinessUnit.BussinessUnit; } internalPolicyNumSetupVM.CreatedBy = internalPolicyNumSetup.CreatedBy != null?Convert.ToInt32(internalPolicyNumSetup.CreatedBy) : 0; internalPolicyNumSetupVM.CreatedDate = internalPolicyNumSetup.CreatedDate != null?internalPolicyNumSetup.CreatedDate.ToString() : string.Empty; internalPolicyNumSetupVM.ModifiedBy = internalPolicyNumSetup.ModifiedBy != null?Convert.ToInt32(internalPolicyNumSetup.ModifiedBy) : 0; internalPolicyNumSetupVM.ModifiedDate = internalPolicyNumSetup.ModifiedDate != null?internalPolicyNumSetup.ModifiedDate.ToString() : string.Empty; internalPolicyNumSetupList.Add(internalPolicyNumSetupVM); } return(internalPolicyNumSetupList); } catch (Exception ex) { throw; } }
public IHttpActionResult UpdateInternalPolicyNumSetup([FromBody] JObject data) { try { int internalPolicyNumSetupID = !string.IsNullOrEmpty(data.SelectToken("InternalPolicyNumSetupID").Value <string>()) ? Convert.ToInt32(data.SelectToken("InternalPolicyNumSetupID").Value <string>()) : 0; string internalPolicyNumber = !string.IsNullOrEmpty(data.SelectToken("InternalPolicyNumber").Value <string>()) ? data.SelectToken("InternalPolicyNumber").Value <string>() : string.Empty; int businessUnitID = !string.IsNullOrEmpty(data.SelectToken("BusinessUnitID").Value <string>()) ? Convert.ToInt32(data.SelectToken("BusinessUnitID").Value <string>()) : 0; int userID = !string.IsNullOrEmpty(data.SelectToken("UserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("UserID").Value <string>()) : 0; if (!manageInternalPolicyNumSetup.IsInternalPolicyNumberAvailable(internalPolicyNumSetupID, internalPolicyNumber)) { InternalPolicyNumSetupVM internalPolicyNumSetupVM = new InternalPolicyNumSetupVM(); internalPolicyNumSetupVM.InternalPolicyNumSetupID = internalPolicyNumSetupID; internalPolicyNumSetupVM.InternalPolicyNumber = internalPolicyNumber; internalPolicyNumSetupVM.BusinessUnitID = businessUnitID; internalPolicyNumSetupVM.ModifiedBy = userID; bool status = manageInternalPolicyNumSetup.UpdateInternalPolicyNumSetup(internalPolicyNumSetupVM); if (status) { return(Json(new { status = true, message = "Successfully Updated" })); } else { return(Json(new { status = false, message = "Update Failed" })); } } else { return(Json(new { status = false, message = "Internal Policy Number already exists" })); } } catch (Exception ex) { return(Json(new { status = false, message = "Unknown error occurred" })); } }