public ActionResult Create(Auction auction) { AuctionsService service = new AuctionsService(); service.SaveAuction(auction); return(View()); }
public ActionResult Create(CreateAuctionsViewModel model) { Auction auction = new Auction(); auction.Title = model.Title; auction.categoryID = model.categoryID; auction.Description = model.Description; auction.ActualAmount = model.ActualAmount; auction.StartingTime = model.StartingTime; auction.EndTime = model.EndTime; //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 service = new AuctionsService(); service.SaveAuction(auction); return(RedirectToAction("Index")); }
public ActionResult Create(CreateAuctionViewModel model) { Auction auction = new Auction(); auction.Title = model.Title; auction.CategoryID = model.CategoryID; auction.Description = model.Description; auction.ActualAmount = model.ActualAmount; auction.StartingTime = model.StartingTime; auction.EndingTime = model.EndingTime; //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()); //foreach (var picID in pictureIDs) //{ // var auctionPicture = new AuctionPicture(); // auctionPicture.PictureID = picID; // auction.AuctionPictures.Add(auctionPicture); //} auctionsService.SaveAuction(auction); return(RedirectToAction("Listing")); }
public ActionResult Create(Auction auction) { AuctionsService auctionsService = new AuctionsService(); auctionsService.SaveAuction(auction); return(RedirectToAction("Index")); }
public JsonResult Create(CreateAuctionViewModel model) { JsonResult result = new JsonResult(); if (ModelState.IsValid) { AuctionsService auctionsService = new AuctionsService(); Auction auction = new Auction(); auction.Title = model.Title; auction.CategoryID = model.CategoryID; 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); //} auctionsService.SaveAuction(auction); result.Data = new { Success = true }; //return RedirectToAction("Index"); } else { result.Data = new { Success = false, Error = "Unable to Save Auctions Please Enter Valid" }; } return(result); }
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.Description = model.Description; auction.ActualAmount = model.ActualAmount; auction.StartingTime = model.StartingTime; auction.EndingTime = model.EndingTime; 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()); /* the above line means: * foreach (var picIDs in pictureIDs) * { * AuctionPicture auctionPicture = new AuctionPicture(); * auctionPicture.PictureID = picIDs; * auction.AuctionPictures.Add(auctionPicture); * }*/ } 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); }
public ActionResult Create(Auctions auctions) { AuctionsService.SaveAuction(auctions); return(RedirectToAction("Index")); }