예제 #1
0
        public ActionResult CreateLot(LotCreateViewModel viewModel, IEnumerable <HttpPostedFileBase> images)
        {
            if (ModelState.IsValid)
            {
                var seller   = _userService.GetUserEntityByLogin(User.Identity.Name);
                var category =
                    _categoryService.GetByCategoryName(viewModel.SettedCategoryName);
                //GetAllCategoryEntities()
                //.FirstOrDefault(c => c.CategoryName == viewModel.SettedCategoryName);
                var lot = viewModel.ToLotEntity();
                lot.BlockReason   = String.Empty;
                lot.CategoryRefId = category.Id;
                lot.IsBlocked     = false;
                lot.IsConfirm     = false;
                lot.IsSold        = false;
                lot.StartDate     = DateTime.Now;
                lot.SellerLogin   = seller.Login;
                lot.SellerEmail   = seller.Email;
                lot.SellerRefId   = seller.Id;

                _lotService.CreateLot(lot);
                StartSchedulerJob(lot.EndDate);

                return(RedirectToAction("Index", "Lot"));
            }
            viewModel.Sections   = LoadSections();
            viewModel.Categories = LoadCategories(viewModel.SettedSectionName);
            return(View(viewModel));
        }
 public ActionResult Create(LotViewModel lot)
 {
     if (ModelState.IsValid)
     {
         if (lot.EndDate < DateTime.Now)
         {
             ModelState.AddModelError(string.Empty, "End Date cannot come before Now");
             return(View(lot));
         }
         if (lot.MinimalBid < 0.01m)
         {
             ModelState.AddModelError(string.Empty, "Starting bid can't be less than 0.1");
             return(View(lot));
         }
         if ((lot.BuyOutBid != null) && (lot.BuyOutBid.Value <= lot.MinimalBid))
         {
             ModelState.AddModelError(string.Empty, "Buyout bid can't be less than or equal to starting bid!");
             return(View(lot));
         }
         lot.CreatedByUserId = UserViewModel.Id;
         WebImage wi = WebImage.GetImageFromRequest();
         if (wi != null)
         {
             wi.Resize(300, 300, true, true);
             lot.LotPicture = wi.GetBytes();
             wi.Resize(100, 100, true, true);
             lot.LotPicturePreview = wi.GetBytes();
         }
         _lotService.CreateLot(lot.ToLotEntity());
         return(RedirectToAction("Index"));
     }
     return(View(lot));
 }
예제 #3
0
        public ActionResult CreateLot(LotModel model)
        {
            var categories = GetCategories();

            model.Categories = GetSelectListItems(categories);

            if (ModelState.IsValid)
            {
                Int32.TryParse(model.SelectedCategoryId, out int selectedId);

                var id = HttpContext.User.Identity.GetUserId();

                LotDTO lotDTO = new LotDTO
                {
                    Name         = model.Name,
                    Description  = model.Description,
                    StartPrice   = model.StartPrice,
                    CurrentPrice = model.StartPrice,
                    BidRate      = model.BidRate,
                    Category     = categoryService.GetCategory(selectedId),
                    UserId       = id,
                    CreatorId    = id
                };

                lotService.CreateLot(lotDTO);

                return(RedirectToAction("Index"));
            }

            return(View("CreateLot", model));
        }
        public void LotCreateTest_CreateLotWithInitPriceLessThenZero_BLValidationExceptionThrown()
        {
            //arrange
            LotDTO lot = new LotDTO {
                InitialPrice = -1, Id = 1, BeginDate = DateTime.Now.AddMinutes(1), EndDate = DateTime.Now.AddDays(1)
            };

            //act

            //assert
            Assert.Throws <BLValidationException>(() => _service.CreateLot(lot), "Lot price must be greater than zero.");
        }
예제 #5
0
 public IHttpActionResult CreateLot(int id)
 {
     try
     {
         lotService.CreateLot(id);
         return(Ok("Lot created successfuly"));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (InvalidOperationException e)
     {
         return(BadRequest(e.Message));
     }
 }
예제 #6
0
        public async Task <ActionResult <LotModel> > Lot([FromBody] CreateLotModel lotBody)
        {
            var uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(@"data:image/png;base64," + lotBody.ImageBase64)
            };
            var uploadResult = _cloudinary.Upload(uploadParams);

            var lotBodyResource = _mapper.Map <CreateLotResource>(lotBody);

            lotBodyResource.ImageUrl = uploadResult.Url.ToString();

            var lot = await _lotService.CreateLot(lotBodyResource);

            var result = _mapper.Map <LotModel>(lot);

            return(CreatedAtAction(nameof(Get), new { id = result.Id }, result));
        }
        public ActionResult <LotDTO> CreateLot([FromForm] LotDTO lot)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (lot.Image != null)
            {
                if (!lot.Image.ContentType.Contains("image"))
                {
                    return(BadRequest("Invalid image format."));
                }

                try
                {
                    lot.ImageUrl = ImageHandler.SaveImage(lot.Image, _environment);
                }
                catch (Exception)
                {
                    return(BadRequest("Image upload error."));
                }
            }

            LotDTO created;

            try
            {
                created = _lotService.CreateLot(lot);
            }
            catch (Exception ex)
            {
                return(BadRequest("Validation error. " + ex.Message));
            }
            return(CreatedAtAction(nameof(GetLot), new { id = created.Id }, created));
        }
예제 #8
0
        public ActionResult Create(LotViewModel model, int categoryId, HttpPostedFileBase image = null)
        {
            if (ModelState.IsValid && image != null)
            {
                model.StartDate  = DateTime.Now;
                model.ImageType  = image.ContentType;
                model.ImageData  = new byte[image.ContentLength];
                model.CategoryId = categoryId;
                model.UserId     = _userService.GetUserByEmail(User.Identity.Name).Id;
                image.InputStream.Read(model.ImageData, 0, image.ContentLength);

                _lotService.CreateLot(model.ToBllLot());

                return(RedirectToAction("Index", "Lot"));
            }
            if (image == null)
            {
                ModelState.AddModelError("", "Add your image");
            }
            SelectList categoriesList = new SelectList(_categoryService.GetAllCategoryEntities(), "Id", "Name");

            ViewBag.CategoriesList = categoriesList;
            return(View(model));
        }
예제 #9
0
 public void CreateLot(Lot lot)
 {
     _lotService.CreateLot(lot);
 }