public List <ChargeTypeVM> GetAllChargeTypes() { try { var chargeTypeData = unitOfWork.TblChargeTypeRepository.Get().ToList(); List <ChargeTypeVM> chargeTypeList = new List <ChargeTypeVM>(); foreach (var chargeType in chargeTypeData) { ChargeTypeVM chargeTypeVM = new ChargeTypeVM(); chargeTypeVM.ChargeTypeID = chargeType.ChargeTypeID; chargeTypeVM.ChargeTypeName = chargeType.ChargeType; chargeTypeVM.Percentage = chargeType.Percentage != null?Convert.ToDouble(chargeType.Percentage) : 0; chargeTypeVM.CreatedBy = chargeType.CreatedBy != null?Convert.ToInt32(chargeType.CreatedBy) : 0; chargeTypeVM.CreatedDate = chargeType.CreatedDate != null?chargeType.CreatedDate.ToString() : string.Empty; chargeTypeVM.ModifiedBy = chargeType.ModifiedBy != null?Convert.ToInt32(chargeType.ModifiedBy) : 0; chargeTypeVM.ModifiedDate = chargeType.ModifiedDate != null?chargeType.ModifiedDate.ToString() : string.Empty; chargeTypeList.Add(chargeTypeVM); } return(chargeTypeList); } catch (Exception ex) { throw; } }
public bool UpdateChargeType(ChargeTypeVM chargeTypeVM) { using (var dbTransaction = unitOfWork.dbContext.Database.BeginTransaction()) { try { tblChargeType chargeType = unitOfWork.TblChargeTypeRepository.GetByID(chargeTypeVM.ChargeTypeID); chargeType.ChargeType = chargeTypeVM.ChargeTypeName; chargeType.Percentage = chargeTypeVM.Percentage; chargeType.ModifiedDate = DateTime.Now; chargeType.ModifiedBy = chargeTypeVM.ModifiedBy; unitOfWork.TblChargeTypeRepository.Update(chargeType); unitOfWork.Save(); //Complete the Transaction dbTransaction.Commit(); return(true); } catch (Exception ex) { //Roll back the Transaction dbTransaction.Rollback(); return(false); } } }
public ChargeTypeVM GetChargeTypeByID(int chargeTypeID) { try { var chargeTypeData = unitOfWork.TblChargeTypeRepository.GetByID(chargeTypeID); ChargeTypeVM chargeTypeVM = new ChargeTypeVM(); chargeTypeVM.ChargeTypeID = chargeTypeData.ChargeTypeID; chargeTypeVM.ChargeTypeName = chargeTypeData.ChargeType; chargeTypeVM.Percentage = chargeTypeData.Percentage != null?Convert.ToDouble(chargeTypeData.Percentage) : 0; chargeTypeVM.CreatedBy = chargeTypeData.CreatedBy != null?Convert.ToInt32(chargeTypeData.CreatedBy) : 0; chargeTypeVM.CreatedDate = chargeTypeData.CreatedDate != null?chargeTypeData.CreatedDate.ToString() : string.Empty; chargeTypeVM.ModifiedBy = chargeTypeData.ModifiedBy != null?Convert.ToInt32(chargeTypeData.ModifiedBy) : 0; chargeTypeVM.ModifiedDate = chargeTypeData.ModifiedDate != null?chargeTypeData.ModifiedDate.ToString() : string.Empty; return(chargeTypeVM); } catch (Exception ex) { throw; } }
public List <InsCommissionStructureHeaderVM> GetAllInsCommisionStructureHeaders(int businessUnitID) { try { var commisionStructureHeaderData = unitOfWork.TblInsCommisionStructureHeaderRepository.Get(x => x.ExtraFloat1 == (double)businessUnitID).ToList(); List <InsCommissionStructureHeaderVM> commisionStructureHeaderList = new List <InsCommissionStructureHeaderVM>(); List <ChargeTypeVM> chargeTpeListVm = new List <ChargeTypeVM>(); foreach (var commisionStructureHeader in commisionStructureHeaderList) { InsCommissionStructureHeaderVM commisionStructureHeaderVM = new InsCommissionStructureHeaderVM(); commisionStructureHeaderVM.CommisionStructureID = commisionStructureHeader.CommisionStructureLineID; commisionStructureHeaderVM.CommisionStructureName = commisionStructureHeader.CommisionStructureName; commisionStructureHeaderVM.BusinessUnitID = commisionStructureHeader.BusinessUnitID > 0 ? Convert.ToInt32(commisionStructureHeader.BusinessUnitID) : 0; commisionStructureHeaderVM.InsuranceCompanyID = commisionStructureHeader.InsuranceCompanyID > 0? commisionStructureHeader.InsuranceCompanyID:0; tblInsCompany insuranceCompany = unitOfWork.TblInsCompanyRepository.GetByID(commisionStructureHeaderVM.InsuranceCompanyID); commisionStructureHeaderVM.InsuranceCompanyName = string.IsNullOrEmpty(insuranceCompany.InsCompany)? "": insuranceCompany.InsCompany; commisionStructureHeaderVM.InsuranceClassID = commisionStructureHeader.InsuranceClassID > 0 ? commisionStructureHeader.InsuranceClassID : 0; tblInsClass insuranceClass = unitOfWork.TblInsClassRepository.GetByID(commisionStructureHeaderVM.InsuranceClassID); commisionStructureHeaderVM.InsuranceClassName = string.IsNullOrEmpty(insuranceClass.Code) ? "" : insuranceClass.Code; commisionStructureHeaderVM.InsuranceSubClassID = commisionStructureHeader.InsuranceSubClassID > 0 ? commisionStructureHeader.InsuranceSubClassID : 0; tblInsSubClass insuranceSubClass = unitOfWork.TblInsSubClassRepository.GetByID(commisionStructureHeaderVM.InsuranceSubClassID); commisionStructureHeaderVM.InsuranceSubClassName = string.IsNullOrEmpty(insuranceSubClass.Description) ? "" : insuranceSubClass.Description; commisionStructureHeaderVM.CreatedDate = commisionStructureHeader.CreatedDate != null?commisionStructureHeader.CreatedDate.ToString() : string.Empty; commisionStructureHeaderVM.ModifiedDate = commisionStructureHeader.ModifiedDate != null?commisionStructureHeader.ModifiedDate.ToString() : string.Empty; commisionStructureHeaderVM.CreatedBy = commisionStructureHeader.CreatedBy > 0 ? commisionStructureHeader.CreatedBy : 0; commisionStructureHeaderVM.ModifiedBy = commisionStructureHeader.ModifiedBy > 0 ? commisionStructureHeader.ModifiedBy : 0; var chargeTypeList = unitOfWork.TblInsCommisionStructureLineRepository.Get(x => x.ComStructID == commisionStructureHeader.CommisionStructureLineID).ToList(); ChargeTypeVM chargeType = new ChargeTypeVM(); foreach (var chargeTpeListLines in chargeTypeList) { chargeType.ChargeTypeID = (int)chargeTpeListLines.ChargeTypeID > 0 ? (int)chargeTpeListLines.ChargeTypeID:0; chargeType.Percentage = Convert.ToDouble(chargeTpeListLines.Percentage) > 0 ? Convert.ToDouble(chargeTpeListLines.Percentage) : 0.0; chargeTpeListVm.Add(chargeType); } commisionStructureHeaderVM.ChargeTypeList = chargeTpeListVm; commisionStructureHeaderList.Add(commisionStructureHeaderVM); } return(commisionStructureHeaderList); } catch (Exception ex) { throw; } }
public IHttpActionResult UpdateChargeType([FromBody] JObject data) { try { int ChargeTypeID = !string.IsNullOrEmpty(data.SelectToken("ChargeTypeID").Value <string>()) ? Convert.ToInt32(data.SelectToken("ChargeTypeID").Value <string>()) : 0; string chargeTypeName = !string.IsNullOrEmpty(data.SelectToken("ChargeTypeName").Value <string>()) ? data.SelectToken("ChargeTypeName").Value <string>() : string.Empty; double percentage = !string.IsNullOrEmpty(data.SelectToken("Percentage").Value <string>()) ? Convert.ToDouble(data.SelectToken("Percentage").Value <string>()) : 0; int userID = !string.IsNullOrEmpty(data.SelectToken("UserID").Value <string>()) ? Convert.ToInt32(data.SelectToken("UserID").Value <string>()) : 0; if (!manageChargeType.IsChargeTypeAvailable(ChargeTypeID, chargeTypeName)) { ChargeTypeVM chargeTypeVM = new ChargeTypeVM(); chargeTypeVM.ChargeTypeID = ChargeTypeID; chargeTypeVM.ChargeTypeName = chargeTypeName; chargeTypeVM.Percentage = percentage; chargeTypeVM.ModifiedBy = userID; bool status = manageChargeType.UpdateChargeType(chargeTypeVM); 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 = "Charge Type Name already exists" })); } } catch (Exception ex) { return(Json(new { status = false, message = "Unknown error occurred" })); } }