示例#1
0
 public static void WriteLog(Exception ex)
 {
     try
     {
         if (ex.InnerException != null)
         {
             WriteLog(ex.InnerException);
         }
         using (dbPetSupplies_8517 DB = new dbPetSupplies_8517())
         {
             Data.EventLog log = new Data.EventLog();
             log.Message    = ex.Message.ToString();
             log.Source     = ex.Source.ToString();
             log.StackTrace = ex.StackTrace.ToString();
             log.IpAddress  = IpAddress();
             log.Datetime   = DateTime.UtcNow;
             log.Url        = HttpContext.Current.Request.Url.ToString();
             DB.EventLogs.Add(log);
             DB.SaveChanges();
         }
     }
     catch
     {
     }
 }
示例#2
0
        /// <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);
        }
示例#3
0
 /// <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);
 }