示例#1
0
 public IHttpActionResult AddNewTradingLot([FromBody] NewTradingLotDTO newTradingLot)
 {
     try
     {
         var fullPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/static/img/");
         lotService.CreateLot(newTradingLot, User.Identity.Name, fullPath);
         return(Created(nameof(GetTradingLot), newTradingLot));
     }
     catch (DatabaseException)
     {
         return(StatusCode(HttpStatusCode.InternalServerError));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (AuctionException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        /// <summary>
        /// Creates new lot
        /// </summary>
        /// <param name="lot">New lot</param>
        /// <param name="userName">User name who creates new lot</param>
        /// <param name="folder">Folder where to save lot picture</param>
        public void CreateLot(NewTradingLotDTO lot, string userName, string folder)
        {
            var lotPoco = Adapter.Adapt <TradingLot>(lot);

            try
            {
                var fileName = $@"{DateTime.Now.Ticks}{lot.Img}";

                SaveImageToFolder(lot.ImgBase64, fileName, folder);
                lotPoco.Img      = fileName;
                lotPoco.User     = Database.UserProfiles.GetProfileByUserName(userName);
                lotPoco.Category = Database.Categories.GetCategoryById(lot.CategoryId);

                Database.TradingLots.AddTradingLot(lotPoco);
                Database.Save();
            }
            catch (Exception)
            {
                throw new DatabaseException();
            }
        }