/// <summary>
        /// Create lot
        /// </summary>
        /// <param name="e">Lot to create</param>
        /// <returns>Id of the created lot</returns>
        public async Task <int> Create(BllLot e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            return(await Context.LotsRepository.Create(e.ToDalLot()));
        }
예제 #2
0
 public static LotModel ToLotMvc(this BllLot lot)
 {
     return(new LotModel()
     {
         Categorie = lot.Categorie.ToString(),
         CreationDate = lot.CreationDate,
         CurrentPrice = lot.CurrentPrice,
         Description = lot.Description,
         EndDate = lot.AuctionEndDate,
         Id = lot.Id,
         LastUpdatedDate = lot.LastUpdateDate,
         Photos = lot.Photos?.Split(':') ?? Enumerable.Empty <string>(),
         Title = lot.Title
     });
 }
예제 #3
0
 public static DalLot ToDalLot(this BllLot lot)
 {
     return(new DalLot()
     {
         Id = lot.Id,
         Categorie = lot.Categorie,
         DateOfCreation = lot.CreationDate,
         Description = lot.Description,
         Expired = lot.AuctionEndDate,
         LastUpdated = lot.LastUpdateDate,
         Photos = lot.Photos,
         Price = lot.CurrentPrice,
         Seller = lot.Seller,
         Title = lot.Title
     });
 }
        /// <summary>
        /// Update lot info
        /// </summary>
        /// <param name="e">Lot with new information</param>
        public async Task Update(BllLot e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var dbLot = await Context.LotsRepository.GetById(e.Id);

            if (dbLot != null)
            {
                await Context.LotsRepository.Update(e.ToDalLot());
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(e));
            }
        }
        public async Task <ActionResult> Create(AddAuctionModel auctionModel)
        {
            if (ModelState.IsValid)
            {
                var    folder = Guid.NewGuid();
                string photos = null;
                foreach (var file in auctionModel.Photos)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        var    filename = Guid.NewGuid();
                        string ext      = Path.GetExtension(file.FileName);
                        string path     = $"/upload/{folder}/";
                        Directory.CreateDirectory(Server.MapPath(path));
                        path   = $"{path}{filename}{ext}";
                        photos = $"{photos}:{path}";
                        file.SaveAs(Server.MapPath(path));
                    }
                }
                photos = photos?.Remove(0, 1);

                BllLot lot = new BllLot()
                {
                    AuctionEndDate = auctionModel.AuctionEndDate,
                    Categorie      = int.Parse(auctionModel.Categorie),
                    CreationDate   = DateTime.Now,
                    CurrentPrice   = auctionModel.StartPrice,
                    Description    = auctionModel.Description,
                    LastUpdateDate = DateTime.Now,
                    Photos         = photos,
                    Seller         = await userService.GetId(User.Identity.Name),
                    Title          = auctionModel.Title
                };

                int auctionId = await auctionService.Create(lot);

                return(RedirectToAction("Details", new { id = auctionId }));
            }
            return(View(auctionModel));
        }