/// <summary> /// Save the Inflation index rate /// </summary> /// <param name="inflationIndexRateVO">Value Object InflationIndexRate</param> public void SaveInflationIndexRate(InflationIndexRateVO inflationIndexRateVO) { if (inflationIndexRateVO.InflationIndexRateId == 0) { //Insert New Record ChargingUplift chargingUplift = new ChargingUplift(); chargingUplift.IndexId = inflationIndexRateVO.InflationIndexId; chargingUplift.UpliftIndex = inflationIndexRateVO.IndexName; chargingUplift.ChargingUpliftDate = inflationIndexRateVO.chargingUpliftDate; chargingUplift.ActualRate = inflationIndexRateVO.IndexRatePerAnnum; chargingUplift.IndexRate = inflationIndexRateVO.IndexRate; chargingUplift.CreationDate = DateTime.Now; chargingUplift.CreatedBy = inflationIndexRateVO.CreatedByUserId; mdbDataContext.ChargingUplifts.InsertOnSubmit(chargingUplift); mdbDataContext.SubmitChanges(); } else { //Update Existing Record ChargingUplift chargingUplift = mdbDataContext.ChargingUplifts.SingleOrDefault(c => c.ID == inflationIndexRateVO.InflationIndexRateId); chargingUplift.IndexId = inflationIndexRateVO.InflationIndexId; chargingUplift.UpliftIndex = inflationIndexRateVO.IndexName; chargingUplift.ChargingUpliftDate = inflationIndexRateVO.chargingUpliftDate; chargingUplift.ActualRate = inflationIndexRateVO.IndexRatePerAnnum; chargingUplift.IndexRate = inflationIndexRateVO.IndexRate; chargingUplift.LastUpdatedDate = DateTime.Now; chargingUplift.LastUpdatedBy = inflationIndexRateVO.LastUpdatedByUserId; mdbDataContext.SubmitChanges(); } }
/// <summary> /// Save the Inflation index rate /// </summary> /// <param name="model">The InflationIndexRate model</param> public ActionResult InflationIndexRateSave(MODEL.InflationIndexRate model) { try { if (ModelState.IsValid) { //Get user id int?userId = Session.GetUserId(); InflationIndexRateService inflationIndexRateService = new InflationIndexRateService(); //InflationIndexRateVO inflationIndexRateVO = new InflationIndexRateVO(model, userId); InflationIndexRateVO inflationIndexRateVO = model.Transpose(userId); inflationIndexRateService.SaveInflationIndexRate(inflationIndexRateVO); return(new HttpStatusCodeResult(200)); } else { foreach (var item in ModelState) { if (item.Key == "chargingUpliftDate" && item.Value.Errors.Count > 0) { return(new HttpStatusCodeAndErrorResult(500, Constants.INVALID_DATE)); } } throw new ApplicationException(String.Format(Constants.CANNOT_SAVE, Constants.INDEXRATE)); } } catch (Exception e) { return(new HttpStatusCodeAndErrorResult(500, e.Message)); } }
/// <summary> /// Constructor /// </summary> /// <param name="inflationIndexRateVO"></param> public InflationIndexRate(InflationIndexRateVO inflationIndexRateVO) { ID = inflationIndexRateVO.InflationIndexRateId; InflationIndexId = inflationIndexRateVO.InflationIndexId; IndexName = inflationIndexRateVO.IndexName; chargingUpliftDate = inflationIndexRateVO.chargingUpliftDate.HasValue ? inflationIndexRateVO.chargingUpliftDate : null; IndexRate = inflationIndexRateVO.IndexRate; IndexRatePerAnnum = inflationIndexRateVO.IndexRatePerAnnum; }
/// <summary> /// Save the Inflation index rate /// </summary> /// <param name="inflationIndexRateVO">Value Object InflationIndexRate</param> public void SaveInflationIndexRate(InflationIndexRateVO inflationIndexRateVO) { //Get and check whether index already exist with same name or not InflationIndexRateVO inflationIndexExist = inflationIndexRateDAL.GetInflationIndexRateByDate(inflationIndexRateVO); if (inflationIndexExist != null && inflationIndexRateVO.InflationIndexRateId != inflationIndexExist.InflationIndexRateId) { throw new ApplicationException(Constants.INDEX_RATE_ALREADY_EXIST); } else { inflationIndexRateDAL.SaveInflationIndexRate(inflationIndexRateVO); } }
/// <summary> /// Get Inflation index rate details date /// </summary> /// <param name="date">date to look for</param> /// <returns>Index rate details</returns> public InflationIndexRateVO GetInflationIndexRateByDate(InflationIndexRateVO inflationIndexRateVO) { ChargingUplift chargingIndex = mdbDataContext.ChargingUplifts.FirstOrDefault(c => c.ChargingUpliftDate != null && c.ChargingUpliftDate.Value.Year.Equals(inflationIndexRateVO.chargingUpliftDate.Value.Year) && c.ChargingUpliftDate.Value.Month.Equals(inflationIndexRateVO.chargingUpliftDate.Value.Month) && c.UpliftIndex == inflationIndexRateVO.IndexName && c.IsDeleted == false); if (chargingIndex != null) { inflationIndexRateVO = new InflationIndexRateVO(chargingIndex); } return(inflationIndexRateVO); }
/// <summary> /// Transpose Model object to Value Object /// </summary> /// <param name="userId">user Id</param> /// <returns>Value object</returns> public InflationIndexRateVO Transpose(int?userId) { InflationIndexRateVO inflationIndexRateVO = new InflationIndexRateVO(); inflationIndexRateVO.InflationIndexRateId = this.ID; inflationIndexRateVO.InflationIndexId = this.InflationIndexId; inflationIndexRateVO.IndexName = this.IndexName; inflationIndexRateVO.chargingUpliftDate = this.chargingUpliftDate; inflationIndexRateVO.IndexRate = this.IndexRate; inflationIndexRateVO.IndexRatePerAnnum = this.IndexRatePerAnnum.HasValue ? this.IndexRatePerAnnum / 100 : this.IndexRatePerAnnum; inflationIndexRateVO.CreatedByUserId = userId; inflationIndexRateVO.LastUpdatedByUserId = userId; return(inflationIndexRateVO); }
/// <summary> /// Get Charging uplift details by index id & uplift date /// </summary> /// <param name="indexId">Index id</param> /// <param name="chargingUpliftDate">Charging uplift date</param> /// <returns></returns> public InflationIndexRateVO GetChargingUpliftByIdAndDate(int?indexId, DateTime?chargingUpliftDate) { ChargingUplift chargingUplift = mdbDataContext.ChargingUplifts.FirstOrDefault(c => c.IndexId == indexId && !c.IsDeleted && (c.ChargingUpliftDate.Value.Month == chargingUpliftDate.Value.Month && c.ChargingUpliftDate.Value.Year == chargingUpliftDate.Value.Year)); InflationIndexRateVO inflationIndexRateVO = null; if (chargingUplift != null) { inflationIndexRateVO = new InflationIndexRateVO(chargingUplift); } return(inflationIndexRateVO); }
/// <summary> /// Get inflation index rate by Id /// </summary> /// <param name="indexRateId">indexRateId</param> /// <returns>Inflation Index Rate Details</returns> public InflationIndexRateVO GetInflationIndexRateById(int?indexRateId, DateTime?upliftDateFrom = null, DateTime?upliftDateTo = null) { ChargingUplift chargingUplift = null; InflationIndexRateVO inflationIndexRateVO = null; if (upliftDateFrom.HasValue && upliftDateTo.HasValue) { chargingUplift = mdbDataContext.ChargingUplifts.FirstOrDefault(c => c.IndexId == indexRateId && !c.IsDeleted && c.ChargingUpliftDate >= upliftDateFrom && c.ChargingUpliftDate <= upliftDateTo); } else { chargingUplift = mdbDataContext.ChargingUplifts.FirstOrDefault(c => c.ID == indexRateId && !c.IsDeleted); } if (chargingUplift != null) { inflationIndexRateVO = new InflationIndexRateVO(chargingUplift); } return(inflationIndexRateVO); }
/// <summary> /// Get Details of inflation index rate by Id /// </summary> /// <param name="id">Index Rate Id</param> /// <returns>The inflation index rate details view</returns> public ActionResult InflationIndexRateEdit(int id) { MODEL.InflationIndexRate inflationIndexRate = null; try { InflationIndexRateService inflationIndexRateService = new InflationIndexRateService(); //Get inflation index rate InflationIndexRateVO inflationIndexRateVO = inflationIndexRateService.GetInflationIndexRateById(id); if (inflationIndexRateVO == null) { ModelState.AddModelError("", String.Format(Constants.ITEM_NOT_FOUND, Constants.INDEXRATE)); } else { inflationIndexRate = new InflationIndexRate(inflationIndexRateVO); } } catch (Exception e) { ModelState.AddModelError("", e.Message); } return(PartialView("InflationIndexRateDetails", inflationIndexRate)); }