public virtual Result Add() { try { Result result = null; #region Validation for dates if (this.PromotionStartDate > this.PromotionEndDate) { result = new Result(); result.Entity = null; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.RejectedBecauseOfPromotionStartDateIsGreaterThenPromotionEndDate.ToString(); return(result); } #endregion #region Check if there is any active promotion period if (this.IsActive == true) { List <PromotionsPeriodsBLL> ActivePromotionsPeriods = GetPromotionsPeriods().Where(x => x.IsActive == true).ToList(); if (ActivePromotionsPeriods.Count > 0) { result = new Result(); result.Entity = null; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.RejectedBecauseOfAlreadyOnePromotionPeriodIsActive.ToString(); return(result); } } #endregion PromotionsPeriods PromotionPeriod = new PromotionsPeriods(); PromotionPeriod.PeriodID = this.Period.PeriodID; PromotionPeriod.YearID = this.Year.MaturityYearID; PromotionPeriod.PromotionStartDate = this.PromotionStartDate; PromotionPeriod.PromotionEndDate = this.PromotionEndDate; PromotionPeriod.IsActive = this.IsActive; PromotionPeriod.CreatedDate = DateTime.Now; PromotionPeriod.CreatedBy = this.LoginIdentity.EmployeeCodeID; this.PromotionPeriodID = new PromotionsPeriodsDAL().Insert(PromotionPeriod); result = new Result(); result.Entity = this; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.Done.ToString(); return(result); } catch { throw; } }
public PromotionsPeriodsBLL MapPromotionPeriod(PromotionsPeriods PromotionPeriod) { return(new PromotionsPeriodsBLL() { PromotionPeriodID = PromotionPeriod.PromotionPeriodID, Period = new PeriodsBLL() { PeriodID = PromotionPeriod.PeriodID, PeriodName = PromotionPeriod.Periods != null ? PromotionPeriod.Periods.PeriodName : "" }, Year = new MaturityYearsBalancesBLL() { MaturityYearID = PromotionPeriod.YearID, MaturityYear = PromotionPeriod.MaturityYearsBalances != null ? PromotionPeriod.MaturityYearsBalances.MaturityYear : 0 }, PromotionStartDate = PromotionPeriod.PromotionStartDate, PromotionEndDate = PromotionPeriod.PromotionEndDate, IsActive = PromotionPeriod.IsActive, CreatedBy = PromotionPeriod.CreatedBy.HasValue ? new EmployeesCodesBLL().MapEmployeeCode(PromotionPeriod.EmployeesCodes) : null, CreatedDate = PromotionPeriod.CreatedDate.Value }); }
public virtual Result Update() { try { Result result = null; #region Validation for dates if (this.PromotionStartDate > this.PromotionEndDate) { result = new Result(); result.Entity = null; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.RejectedBecauseOfPromotionStartDateIsGreaterThenPromotionEndDate.ToString(); return(result); } #endregion #region Check if there is any promotion record exist List <PromotionsRecordsBLL> PromotionsRecords = new PromotionsRecordsBLL().GetPromotionsRecords().Where(x => x.PromotionPeriod.PromotionPeriodID.Equals(this.PromotionPeriodID)).ToList(); if (PromotionsRecords.Count > 0) { result = IsNoConflictWithPromotionStartAndPromotionEndDates(this.PromotionStartDate, this.PromotionEndDate); if (result != null) { return(result); } } #endregion #region Check if there is any active promotion period if (this.IsActive == true) { List <PromotionsPeriodsBLL> ActivePromotionsPeriods = GetPromotionsPeriods().Where(x => x.IsActive == true && x.PromotionPeriodID != this.PromotionPeriodID).ToList(); if (ActivePromotionsPeriods.Count > 0) { result = new Result(); result.Entity = null; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.RejectedBecauseOfAlreadyOnePromotionPeriodIsActive.ToString(); return(result); } } #endregion PromotionsPeriods PromotionPeriod = new PromotionsPeriods(); PromotionPeriod.PromotionPeriodID = this.PromotionPeriodID; PromotionPeriod.PeriodID = this.Period.PeriodID; PromotionPeriod.YearID = this.Year.MaturityYearID; PromotionPeriod.PromotionStartDate = this.PromotionStartDate; PromotionPeriod.PromotionEndDate = this.PromotionEndDate; PromotionPeriod.IsActive = this.IsActive; PromotionPeriod.LastUpdatedDate = DateTime.Now; PromotionPeriod.LastUpdatedBy = this.LoginIdentity.EmployeeCodeID; int UpdateResult = new PromotionsPeriodsDAL().Update(PromotionPeriod); if (UpdateResult != 0) { result = new Result(); result.Entity = this; result.EnumType = typeof(PromotionsPeriodsValidationEnum); result.EnumMember = PromotionsPeriodsValidationEnum.Done.ToString(); } return(result); } catch { throw; } }