Beispiel #1
0
        public JsonResult Create(CreateAuctionViewModel model)
        {
            JsonResult result = new JsonResult();


            if (ModelState.IsValid)
            {
                Auction auction = new Auction();

                auction.Title        = model.Title;
                auction.CategoryID   = model.CategoryID;
                auction.Summary      = model.Summary;
                auction.Description  = model.Description;
                auction.ActualAmount = model.ActualAmount;
                auction.StartTime    = model.StartTime;
                auction.EndTime      = model.EndTime;

                //check if we have AuctionPictureIds posted back from form
                if (!string.IsNullOrEmpty(model.AuctionPictures))
                {
                    //LINQ
                    var pictureIDs = model.AuctionPictures
                                     .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(ID => int.Parse(ID)).ToList();


                    auction.AuctionPictures = new List <AuctionPicture>();
                    auction.AuctionPictures.AddRange(pictureIDs.Select(x => new AuctionPicture()
                    {
                        PictureID = x
                    }).ToList());
                }

                auctionsService.SaveAuction(auction);

                result.Data = new { Success = true };
            }
            else
            {
                result.Data = new { Success = false, Error = "Unable to save Auction. Please enter valid values." };
            }

            return(result);
        }
Beispiel #2
0
        public JsonResult Create(CreateAuctionViewModel model)
        {
            JsonResult result = new JsonResult();

            if (ModelState.IsValid)
            {
                Auction auction = new Auction();
                auction.CategoryID   = model.CategoryID;
                auction.Title        = model.Title;
                auction.Description  = model.Description;
                auction.ActualAmount = model.ActualAmount;
                auction.StartingTime = model.StartingTime;
                auction.EndingTime   = model.EndingTime;

                if (!string.IsNullOrEmpty(model.auctionPictures))
                {
                    var pictureIDs = model.auctionPictures.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(ID => int.Parse(ID)).ToList();
                    auction.AuctionPictures = new List <AuctionPicture>();
                    auction.AuctionPictures.AddRange(pictureIDs.Select(x => new AuctionPicture()
                    {
                        PictureID = x
                    }).ToList());
                }
                //foreach (var picID in pictureIDs)
                //{
                //    var auctionPicture = new AuctionPicture();
                //    auctionPicture.PictureID = picID;

                //    auction.AuctionPictures.Add(auctionPicture);
                //}

                AuctionsServices.SaveAuction(auction);
                //return RedirectToAction("Listing");
                result.Data = new { Success = true };
            }
            else
            {
                result.Data = new { Success = false, Error = "Unable to save Auction.Please inter valid values" };
                //return PartialView(model);
            }

            return(result);
        }