/// <summary> /// to delete page /// </summary> /// <param name="encryptedId">encrypted page id</param> /// <returns></returns> public TransactionMessage DeleteCouponAdMonth(string encryptedId, string monthId) { TransactionMessage model = new TransactionMessage(); model.Status = MessageStatus.Error; model.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "InvalidRequest"); try { if (encryptedId.IsValidEncryptedID()) { int _couponId = Convert.ToInt32(encryptedId.ToDecrypt()); int _monthId = Convert.ToInt32(monthId); using (dbPetSupplies_8517 db = new dbPetSupplies_8517()) { var item = db.Coupons.Where(x => x.CouponID == _couponId && x.AdMonths1.Where(a => a.AdMonthID == _monthId).Count() > 0).FirstOrDefault(); Coupon dbCoupon = db.Coupons.Where(x => x.CouponID == _couponId).FirstOrDefault(); AdMonth dbAdMonth = db.AdMonths.Where(x => x.AdMonthID == _monthId).FirstOrDefault(); var associated = db.StoreAdChoices.Where(x => x.AdMonthID == _monthId && x.CouponID == _couponId).Count() > 0 ? true : false; if (associated) { model.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "AssociatedCoupon"); model.Status = MessageStatus.Error; } else if (dbAdMonth.AdCoupnID == _couponId) { model.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "DefaultCoupon"); model.Status = MessageStatus.Error; } else { if (item != null && dbCoupon != null && dbAdMonth != null) { dbAdMonth.Coupons.Remove(dbCoupon); db.SaveChanges(); model.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "Delete"); model.Status = MessageStatus.Success; } } } } } catch (Exception ex) { EventLogHandler.WriteLog(ex); } return(model); }
/// <summary> /// to save or update Page /// </summary> /// <param name="model">UsersModel</param> /// <returns>UsersModel</returns> public CouponAdMonthModel CouponAdMonthSave(CouponAdMonthModel model) { model.TransMessage = new TransactionMessage(); model.TransMessage.Status = MessageStatus.Error; try { using (dbPetSupplies_8517 db = new dbPetSupplies_8517()) { #region check duplicate if (db.Coupons.Where(x => x.CouponID == model.CouponID && x.AdMonths1.Where(a => a.AdMonthID == model.MonthId).Count() > 0).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "Duplicate"); return(model); } #endregion Coupon dbCoupon = db.Coupons.Where(x => x.CouponID == model.CouponID).FirstOrDefault(); AdMonth dbAdMonth = db.AdMonths.Where(x => x.AdMonthID == model.MonthId).FirstOrDefault(); if (dbCoupon != null && dbAdMonth != null) { //int refCount = UnitofWork.RepoStoreAdChoice.Where(x => x.CouponID == model.CouponID).Count(); //if (refCount == 0) //{ dbAdMonth.Coupons.Add(dbCoupon); db.SaveChanges(); model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "Save"); model.TransMessage.Status = MessageStatus.Success; //} //else //{ // model.TransMessage.Message = utilityHelper.ReadGlobalMessage("ManageCouponAdMonth", "NotAssign"); //} } } } catch (Exception ex) { EventLogHandler.WriteLog(ex); } return(model); }
/// <summary> /// to save or update Page /// </summary> /// <param name="model">UsersModel</param> /// <returns>UsersModel</returns> public AdMonthModel Save(AdMonthModel model) { model.TransMessage = new TransactionMessage(); model.TransMessage.Status = MessageStatus.Error; try { #region check duplicate if (UnitofWork.RepoAdMonth.Where(x => x.Year == model.Year && x.Month == model.Month && x.DropNumber == model.DropNumber && x.AdMonthID != model.AdMonthID).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "Duplicate"); return(model); } #endregion #region Valid Date and Month //commented on 5th augest 16 //if (model.LockOutStartDate.Month != model.Month || model.LockOutEndDate.Month != model.Month) //{ // model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "InvalidDateMonth"); // return model; //} #endregion #region Lock out Start/End Date if (UnitofWork.RepoAdMonth.Where(x => ((x.LockOutStartDate < model.LockOutStartDate && x.LockOutEndDate > model.LockOutEndDate) || (x.LockOutStartDate >= model.LockOutStartDate && x.LockOutStartDate <= model.LockOutEndDate) || (x.LockOutEndDate >= model.LockOutStartDate && x.LockOutEndDate <= model.LockOutEndDate)) && x.AdMonthID != model.AdMonthID).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "Date"); return(model); } #endregion #region Check is Auto pouplated if (UnitofWork.RepoExceptionReport.Where(x => x.MonthId == model.AdMonthID).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "AutoPopulated"); return(model); } #endregion AdMonth dbAdMonth = UnitofWork.RepoAdMonth.Where(x => x.AdMonthID == model.AdMonthID).FirstOrDefault(); bool isSave = false; if (dbAdMonth == null) { #region Save dbAdMonth = new AdMonth(); UnitofWork.RepoAdMonth.Add(dbAdMonth); model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "Save"); isSave = true; #endregion } else { #region Update model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdMonth", "Update"); #endregion } #region Set Value dbAdMonth.AdOptionID = model.AdOptionID; dbAdMonth.CorpInHomeDate = model.CorpInHomeDate; //dbAdMonth.InHomeEnd = model.InHomeEnd; //dbAdMonth.InHomeStart = model.InHomeStart; dbAdMonth.DropNumber = model.DropNumber; dbAdMonth.LockOutEndDate = model.LockOutEndDate; dbAdMonth.LockOutStartDate = model.LockOutStartDate; dbAdMonth.Month = model.Month; dbAdMonth.PetpartnerInfo = model.PetpartnerInfo; dbAdMonth.Year = model.Year; dbAdMonth.CorpPlanText = model.CorpPlanText; dbAdMonth.AdCoupnID = model.AdCouponID; Coupon defaultcoupon = UnitofWork.RepoCoupon.Where(c => c.CouponID == model.AdCouponID).FirstOrDefault(); dbAdMonth.Coupons.Add(defaultcoupon); #endregion UnitofWork.Commit(); model.AdMonthID = dbAdMonth.AdMonthID; model.TransMessage.Status = MessageStatus.Success; } catch (Exception ex) { EventLogHandler.WriteLog(ex); } return(model); }