예제 #1
0
        static OfferController()
        {
            _storage = new OfferVm();
            var cats = new[] {
                new Category {
                    Id = CategoryType.First, Text = "Первая"
                },
                new Category {
                    Id = CategoryType.Second, Text = "2я"
                },
                new Category {
                    Id = CategoryType.Third, Text = "3я"
                },
                new Category {
                    Id = CategoryType.Fourth, Text = "4я"
                },
                new Category {
                    Id = CategoryType.Fifth, Text = "5я"
                },
                new Category {
                    Id = CategoryType.Sixth, Text = "6я"
                },
                new Category {
                    Id = CategoryType.Seventh, Text = "7я"
                }
            };

            _storage.Categories = cats.Select(c => new SelectListItem {
                Value = c.Id.ToString(), Text = c.Text
            });
            _storage.SelectedItems = new CategoryType[] { CategoryType.Fifth, CategoryType.Second, CategoryType.First };
        }
예제 #2
0
        // GET: Offer/Details/5
        public ActionResult Details(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Offer   p  = service.GetById(id);
            OfferVm p1 = new OfferVm()
            {
                Description = p.Description,
                OfferName   = p.OfferName,
                Price       = p.Price,

                EndDate   = p.EndDate,
                StartDate = p.StartDate,
                ImgUrl    = p.ImgUrl,
            };

            if (p == null)
            {
                return(HttpNotFound());
            }

            return(View(p1));
        }
예제 #3
0
        public ActionResult Edit(int id, OfferVm ovm, HttpPostedFileBase file)
        {
            var    allowedExtensions = new string[] { ".jpeg", ".png", ".jpg" };
            string extension         = Path.GetExtension(file.FileName);

            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }


                //ajout d'image sous dossier
                var fileName = "";
                if (file.ContentLength > 0)
                {
                    fileName = Path.GetFileName(file.FileName);
                    var path = Path.
                               Combine(Server.MapPath("~/Content/Uploads/"),
                                       fileName);
                    file.SaveAs(path);
                }
                Offer p = service.GetById(id);

                p.Description = ovm.Description;
                p.EndDate     = ovm.EndDate;
                p.OfferName   = ovm.OfferName;
                p.StartDate   = ovm.StartDate;
                p.ImgUrl      = file.FileName;
                p.Price       = ovm.Price;



                if (p == null)
                {
                    return(HttpNotFound());
                }
                if (allowedExtensions.Contains(extension))
                {
                    service.Update(p);
                    service.Commit();
                    // Service.Dispose();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit"));
                }


                // TODO: Add delete logic here
                return(View(ovm));
            }
            catch
            {
                return(View());
            }
        }
예제 #4
0
        public async Task <ActionResult> Add(OfferVm data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var offer = new Offer
                        {
                            Title              = data.Title,
                            OfferId            = data.OfferId,
                            FlatDiscount       = data.FlatDiscount,
                            DiscountId         = data.DiscountId,
                            SpecificItems      = data.SpecificItems,
                            DiscountPercentage = data.DiscountPercentage,
                            SpecificValue      = data.SpecificValue,
                        };

                        _db.Entry(offer).State = EntityState.Added;
                        await _db.SaveChangesAsync();
                    }

                    TempData["Success"] = SuccessMessage.Added;
                    return(RedirectToAction("Index", "Offer", new { area = "ControlPanel" }));
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(0)));
        }
예제 #5
0
        public ActionResult CreateOffer(IFormCollection collection, OfferVm offerVm, string[] Accessories)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                try
                {
                    var assec = "";
                    for (int i = 0; i < Accessories.Length; i++)
                    {
                        assec += Accessories[i] + ", ";
                    }
                    assec = assec.Substring(0, assec.Length - 2);

                    var customer = new Customer
                    {
                        Id      = 0,
                        Name    = offerVm.Name,
                        Address = offerVm.Address,
                        Ac      = offerVm.Ac
                    };
                    _context.Customers.Add(customer);
                    _context.SaveChanges();

                    var offer = new Offer
                    {
                        Id           = 0,
                        Type         = offerVm.Type,
                        Chassis      = offerVm.Chassis,
                        Engine       = offerVm.Engine,
                        ManfYear     = offerVm.ManfYear,
                        Cc           = offerVm.Cc,
                        Colour       = offerVm.Colour,
                        LoadCapacity = offerVm.LoadCapacity,
                        Accessories  = assec,
                        Price        = offerVm.Price,
                        OfferDate    = DateTime.Now,
                        Delivery     = offerVm.Delivery,
                        Validity     = offerVm.Validity,
                        CustomerId   = customer.Id
                    };
                    _context.Offers.Add(offer);
                    _context.SaveChanges();

                    transaction.Commit();

                    return(RedirectToAction("GetOffer"));
                }
                catch
                {
                    transaction.Rollback();
                    return(View());
                }
            }
        }
예제 #6
0
        public IActionResult UpdateFoodOffer(int id)
        {
            var     offer   = _context.Offer.AsNoTracking().Where(q => q.OfferId == id).FirstOrDefault();
            OfferVm offervm = new OfferVm()
            {
                OfferId       = offer.OfferId,
                Coupon        = offer.Coupon,
                Discount      = offer.Discount,
                ValidatyStart = offer.ValidatyStart,
                ValidatyTo    = offer.ValidatyTo
            };

            return(View(offervm));
        }
예제 #7
0
        public IActionResult UpdateFoodOffer(OfferVm offervm)
        {
            Offer offer = new Offer()
            {
                OfferId       = offervm.OfferId,
                Coupon        = offervm.Coupon,
                Discount      = offervm.Discount,
                ValidatyStart = offervm.ValidatyStart,
                ValidatyTo    = offervm.ValidatyTo
            };

            _context.Offer.Update(offer);
            _context.SaveChanges();
            ModelState.Clear();
            return(RedirectToAction("OfferDetails"));
        }
예제 #8
0
        public ActionResult Create(OfferVm ovm, HttpPostedFileBase file)
        {
            if (
                file == null ||
                file.ContentLength == 0)
            {
                return(RedirectToAction("Create"));
            }


            Offer offerdomain = new Offer()
            {
                StartDate   = ovm.StartDate,
                OfferName   = ovm.OfferName,
                Price       = ovm.Price,
                EndDate     = ovm.EndDate,
                ProductId   = ovm.ProductId,
                Description = ovm.Description,
                ImgUrl      = file.FileName,
            };

            service.Add(offerdomain);
            service.Commit();


            var path = "";
            //ajout d'image sous dossier
            var fileName = "";

            if (file.ContentLength > 0)
            {
                fileName = Path.GetFileName(file.FileName);
                path     = Path.
                           Combine(Server.MapPath("~/Content/Uploads/"),
                                   fileName);
                file.SaveAs(path);
            }
            var path2 = path;

            return(RedirectToAction("Index"));
        }
예제 #9
0
        public async Task <ActionResult> Edit(OfferVm data)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (_db = new DBEntities())
                    {
                        var offer = await _db.Offers.FindAsync(data.OfferId);

                        if (offer == null)
                        {
                            ModelState.AddModelError(ErrorMessage.DataNotFound, ErrorMessage.DataNotFound);
                        }
                        else
                        {
                            offer.OfferId            = data.OfferId;
                            offer.FlatDiscount       = data.FlatDiscount;
                            offer.DiscountId         = data.DiscountId;
                            offer.SpecificItems      = data.SpecificItems;
                            offer.DiscountPercentage = data.DiscountPercentage;
                            offer.SpecificValue      = data.SpecificValue;
                            offer.Title = data.Title;

                            _db.Entry(offer).State = EntityState.Modified;
                            await _db.SaveChangesAsync();

                            TempData["Success"] = SuccessMessage.Updated;
                            return(RedirectToAction("Index", "Offer", new { area = "ControlPanel", id = data.OfferId }));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = e.Message;
            }
            return(View("Index", await GetModelData(data.OfferId)));
        }
예제 #10
0
        public ActionResult Delete(int id, OfferVm aftervm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (id == null)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }
                    Offer   p  = service.GetById(id);
                    OfferVm p1 = new OfferVm()
                    {
                        Description = p.Description,
                        EndDate     = p.EndDate,
                        StartDate   = p.StartDate,
                        ImgUrl      = p.ImgUrl,
                        OfferName   = p.OfferName,
                        Price       = p.Price,
                    };
                    if (p == null)
                    {
                        return(HttpNotFound());
                    }
                    service.Delete(p);
                    service.Commit();

                    return(RedirectToAction("Index"));
                }
                // TODO: Add delete logic here
                return(View(aftervm));
            }
            catch
            {
                return(View());
            }
        }
예제 #11
0
        public IActionResult OfferDetails(int Page = 1)
        {
            var offerdetails     = _context.Offer.AsNoTracking().ToList();
            var offerdetailslist = new List <OfferVm>();
            int count            = 1;

            foreach (var item in offerdetails)
            {
                OfferVm offervm = new OfferVm()
                {
                    Serial         = count,
                    OfferId        = item.OfferId,
                    Coupon         = item.Coupon,
                    Discount       = item.Discount,
                    ValidatyStart_ = item.ValidatyStart.ToShortDateString(),
                    ValidatyTo_    = item.ValidatyTo.ToShortDateString()
                };
                offerdetailslist.Add(offervm);
                count++;
            }
            var sent = offerdetailslist.ToPagedList(Page, 5);

            return(View(sent));
        }
예제 #12
0
        public IActionResult AddNewOffer(OfferVm offervm)
        {
            var valid = _context.Offer.AsNoTracking().
                        Where(t => t.Coupon == offervm.Coupon).FirstOrDefault();

            if (valid != null)
            {
                ViewBag.Validation = "You have already added Coupon " + offervm.Coupon + ".";
                return(View());
            }
            Offer offer = new Offer()
            {
                Coupon        = offervm.Coupon,
                Discount      = offervm.Discount,
                ValidatyStart = offervm.ValidatyStart,
                ValidatyTo    = offervm.ValidatyTo
            };

            _context.Offer.Add(offer);
            _context.SaveChanges();
            ViewBag.Success = "You have succesfully added Coupon " + offervm.Coupon + ".";
            ModelState.Clear();
            return(View());
        }
예제 #13
0
 public IActionResult Index(OfferVm vm)
 {
     _storage.SelectedItems = vm.SelectedItems.ToArray();
     return(View(_storage));
 }