Ejemplo n.º 1
0
        public ActionResult CreateDeal(DealViewModel _deal, IEnumerable <HttpPostedFileBase> files)
        {
            var userId = Convert.ToInt32(Session[KeyList.SessionKeys.UserID].ToString());

            DealViewModel dropdown = DropDownForstore(userId);

            try
            {
                if (ModelState.IsValid)
                {
                    var stores = storeService.Get(x => x.UserId == userId);
                    var image  = files.IsValidImageList(false);
                    if (image == false)
                    {
                        ViewBag.message = "Image is required and should only have .pdf,.jpeg,.jpg,.gif";
                        return(View(dropdown));
                    }
                    else
                    {
                        foreach (var store in stores)
                        {
                            if (store.StoreId == _deal.StoreId)
                            {
                                var strikePrice = _deal.Price - (decimal)((double)_deal.Discount / 100 * _deal.Price);
                                if (store.IsValid == true)
                                {
                                    Deal deal = new Deal
                                    {
                                        StoreId     = _deal.StoreId,
                                        Description = _deal.Description,
                                        Title       = _deal.Title,
                                        ValidTill   = _deal.ValidTill.Date,
                                        Price       = _deal.Price,
                                        Discount    = _deal.Discount,
                                        StrikePrice = strikePrice,
                                        AddedOn     = DateTime.Now,
                                        IsDeleted   = false,
                                        IsDealFree  = _deal.IsDealfree
                                    };
                                    int id = dealServices.CreateDeal(deal);

                                    foreach (var item in files)
                                    {
                                        var       path       = item.SaveImageFile();
                                        DealImage _dealImage = new DealImage()
                                        {
                                            DealId     = id,
                                            DealImage1 = path
                                        };

                                        dealImageServices.CreateDealImage(_dealImage);
                                    }
                                }
                                else
                                {
                                    ViewBag.message = "your store registration certificate is not valid";
                                    return(View(dropdown));
                                }
                            }
                        }
                    }
                    Logs GenerateLog = new Logs();
                    GenerateLog.CreateLog(userId, KeyList.LogMessages.EditStore);
                    return(RedirectToAction("Deal"));
                }
                return(View(dropdown));
            }
            catch (Exception e)
            {
                return(View(dropdown));
            }
        }