Example #1
0
 public PromotionActionView GetByID(long id)
 {
     try
     {
         var _item = DbContext.Promotions.Find(id);
         if (_item != null && _item.ID != 0)
         {
             PromotionActionView promotion = new PromotionActionView();
             promotion.Avatar      = _item.Avatar;
             promotion.Content     = _item.Content;
             promotion.Desc        = _item.Desc;
             promotion.EndDate     = String.Format("{0:dd/MM/yyyy}", _item.EndDate);
             promotion.ID          = _item.ID;
             promotion.StartDate   = String.Format("{0:dd/MM/yyyy}", _item.StartDate);
             promotion.Title       = _item.Title;
             promotion.Type        = _item.Type;
             promotion.Limit       = _item.Limit;
             promotion.MemberLevel = _item.MemberLevel;
             promotion.MemberPoint = _item.MemberPoint;
             promotion.StartAge    = _item.StartAge;
             promotion.EndAge      = _item.EndAge;
             promotion.Gender      = _item.Gender;
             promotion.Status      = _item.Status;
             promotion.Code        = _item.Code;
             return(promotion);
         }
         return(null);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #2
0
 public ActionResult Add(PromotionActionView model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             HttpCookie          reqCookies = Request.Cookies["VendorLoginCookie"];
             ResponseVendorLogin login      = JsonConvert.DeserializeObject <ResponseVendorLogin>(reqCookies.Value.ToString().UrlDecode());
             if (login == null)
             {
                 return(Redirect("/System/Login"));
             }
             model.Vendor = login.ID;
             if (_promotionBusiness.Add(model))
             {
                 _promotionBusiness.Save();
                 return(RedirectToAction("List"));
             }
         }
         return(View());
     }
     catch (Exception)
     {
         return(View());
     }
 }
Example #3
0
        public bool Add(PromotionActionView model)
        {
            try
            {
                int      year, month, day;
                DateTime start = DateTime.Now;
                DateTime end   = DateTime.Now;

                if (model.StartDate == "" || model.EndDate == "")
                {
                    year  = DateTime.Now.Year;
                    month = DateTime.Now.Month;
                    day   = DateTime.Now.Day;
                    start = new DateTime(year, month, day, 0, 0, 0);
                    year  = DateTime.Now.AddYears(1).Year;
                    month = DateTime.Now.AddYears(1).Month;
                    day   = DateTime.Now.AddYears(1).Day;
                    end   = new DateTime(year, month, day, 23, 59, 0);
                }
                else
                {
                    year  = Convert.ToInt32(model.StartDate.Split('/')[2]);
                    month = Convert.ToInt32(model.StartDate.Split('/')[1]);
                    day   = Convert.ToInt32(model.StartDate.Split('/')[0]);
                    start = new DateTime(year, month, day, 0, 0, 0);
                    year  = Convert.ToInt32(model.EndDate.Split('/')[2]);
                    month = Convert.ToInt32(model.EndDate.Split('/')[1]);
                    day   = Convert.ToInt32(model.EndDate.Split('/')[0]);
                    end   = new DateTime(year, month, day, 0, 0, 0);
                }

                Promotion promotion = new Promotion();
                promotion.Avatar      = "http://localhost:44351" + model.Avatar;
                promotion.Content     = model.Content.Replace("\"/Content/FileUploads/", "\"http://localhost:44351/Content/FileUploads/");
                promotion.Desc        = model.Desc;
                promotion.EndAge      = model.EndAge;
                promotion.EndDate     = end;
                promotion.Gender      = model.Gender;
                promotion.ID          = model.ID;
                promotion.Limit       = model.Limit;
                promotion.MemberLevel = model.MemberLevel;
                promotion.MemberPoint = model.MemberPoint;
                promotion.StartAge    = model.StartAge;
                promotion.StartDate   = start;
                promotion.Status      = model.Status;
                promotion.Title       = model.Title;
                promotion.Type        = model.Type;
                promotion.Staff       = model.Staff;
                promotion.Code        = model.Code;

                DbContext.Promotions.Add(promotion);

                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
Example #4
0
 public ActionResult Add(PromotionActionView model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (_promotionBusiness.Add(model))
             {
                 _promotionBusiness.Save();
                 return(RedirectToAction("List"));
             }
         }
         return(View());
     }
     catch (Exception)
     {
         return(View());
     }
 }
Example #5
0
 public bool Edit(PromotionActionView entity)
 {
     return(_promotion.Edit(entity));
 }
Example #6
0
 public bool Add(PromotionActionView entity)
 {
     return(_promotion.Add(entity));
 }