Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public ActionResult CategoryInSectionPartial(string sectionName)
        {
            var lotViewModel = new LotCreateViewModel()
            {
                Categories = LoadCategories(sectionName)
            };

            return(PartialView("_CategoryInSection", lotViewModel));
        }
Ejemplo n.º 3
0
 public static LotEntity ToLotEntity(this LotCreateViewModel viewModel)
 {
     return(new LotEntity()
     {
         Id = viewModel.Id,
         IsBlocked = false,
         CategoryName = viewModel.SettedCategoryName,
         Discription = viewModel.Discription,
         EndDate = viewModel.EndDate,
         LotName = viewModel.Name,
         SellerLogin = viewModel.SellerLogin,
         StartingBid = viewModel.StartingBid
     });
 }
Ejemplo n.º 4
0
        private string ProcessUploadedFile(LotCreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.Attachment != null)
            {
                string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "coa");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Attachment.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Attachment.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Ejemplo n.º 5
0
        private void AddValidationErrors(LotCreateViewModel lotViewModel)
        {
            if (lotViewModel.EndTime < DateTime.Now)
            {
                ModelState.AddModelError("EndTime", "Invalid end time.");
            }

            if (lotViewModel.MinBid == 0)
            {
                ModelState.AddModelError("MinBid", "Minimum bid amount must be grater than 0.");
            }

            if (lotViewModel.StartPrice <= 0)
            {
                ModelState.AddModelError("StartPrice", "Start price must be grater than 0.");
            }
        }
Ejemplo n.º 6
0
 public ActionResult CreateLot()
 {
     try
     {
         var sections     = LoadSections();
         var lotViewModel = new LotCreateViewModel()
         {
             Sections   = sections,
             Categories = LoadCategories(sections.First().Text)
         };
         return(View(lotViewModel));
     }
     catch (Exception EX_NAME)
     {
         Log.LogError(EX_NAME);
         return(RedirectToAction("Index", "Lot"));
     }
 }
Ejemplo n.º 7
0
 public ActionResult EditLot(LotCreateViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var lot      = _lotService.GetLotEntity(viewModel.Id);
         var category =
             _categoryService.GetAllCategoryEntities()
             .FirstOrDefault(c => c.CategoryName == viewModel.SettedCategoryName);
         if (category != null)
         {
             lot.CategoryRefId = category.Id;
         }
         lot.LotName     = viewModel.Name;
         lot.Discription = viewModel.Discription;
         lot.EndDate     = viewModel.EndDate;
         lot.IsConfirm   = false;
         _lotService.UpdateLot(lot);
         StartSchedulerJob(lot.EndDate);
         return(RedirectToAction("LotDetails", "Lot", new { id = viewModel.Id }));
     }
     return(View(viewModel));
 }
Ejemplo n.º 8
0
        public ActionResult EditLot(int id)
        {
            var lot       = _lotService.GetLotEntity(id);
            var sectionId = _categoryService.GetCategoryEntity(lot.CategoryRefId).SectionRefId;
            var sections  = LoadSections();
            var section   =
                _sectionService.GetSectionEntity(_categoryService.GetCategoryEntity(lot.CategoryRefId).SectionRefId);
            var lotViewModel = new LotCreateViewModel()
            {
                Sections           = sections,
                Categories         = LoadCategories(section.SectionName),
                Id                 = lot.Id,
                Name               = lot.LotName,
                SettedSectionName  = _sectionService.GetSectionEntity(sectionId).SectionName,
                Discription        = lot.Discription,
                EndDate            = lot.EndDate,
                SettedCategoryName = lot.CategoryName,
                StartingBid        = lot.StartingBid
            };

            return(View(lotViewModel));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateLot([FromBody] LotCreateViewModel lotViewModel)
        {
            if (lotViewModel == null)
            {
                return(BadRequest(ModelState));
            }

            AddValidationErrors(lotViewModel);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lot = _maper.Map <LotCreateViewModel, Lot>(lotViewModel);

            lot.AppUserID = User.FindFirstValue(ClaimTypes.NameIdentifier);

            await _lotService.CreateLotAsync(lot);

            return(Ok(lot));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> UpdateLot(int id, [FromBody] LotCreateViewModel lotViewModel)
        {
            if (lotViewModel == null)
            {
                return(BadRequest(ModelState));
            }

            AddValidationErrors(lotViewModel);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updatedLot = _maper.Map <LotCreateViewModel, Lot>(lotViewModel);
            var result     = await _lotService.UpdateLotAsync(id, updatedLot);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(_maper.Map <Lot, LotCreateViewModel>(result)));
        }
Ejemplo n.º 11
0
        public IActionResult Create(LotCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.Attachment != null)
                {
                    uniqueFileName = ProcessUploadedFile(model);
                }

                Lot newLot = new Lot
                {
                    LotName           = model.LotName,
                    CreationTimeStamp = model.CreationTimeStamp,
                    Weight            = model.Weight,
                    AttachmentPath    = uniqueFileName,
                    Reagents          = model.Reagents
                };

                lotRepo.Create(newLot);
                return(RedirectToAction("details", new { id = newLot.Id }));
            }
            return(View());
        }