internal ServiceResult AddAuction(AuctionCreateViewModel vm) { vm = StripStringsAuctionCreate(vm); ServiceResult validAuction = ValidateAuction(vm.Auction); ServiceResult validSeller = ValidateSeller(vm.Seller); if (validAuction.Success && validSeller.Success) { bool checkSellerEmailExist = DuplicateEmailCheck(vm.Seller.Email); if (checkSellerEmailExist) { Auction addAuctionSuccess = SaveAuction(vm.Auction); Guid addUserSuccess = SaveSeller(vm.Seller, addAuctionSuccess.AuctionGUID); bool commitSuccess = Commit(); if (commitSuccess) { return(new ServiceResult() { Success = true, Params = addUserSuccess.ToString() }); } } } return(new ServiceResult() { ErrorMessage = validAuction.ErrorMessage, Success = false }); }
public async Task <IActionResult> Create(AuctionCreateViewModel model) { if (model.ExistentProductId == 0) { HttpResponseMessage newProductResponse = await PostAsync("products", model.NewProduct.MapToRequest()); if (!newProductResponse.IsSuccessStatusCode) { TempData["AuctionErrorMessage"] = await newProductResponse.Content.ReadAsStringAsync(); return(RedirectToAction(nameof(Create))); } var existentProduct = await newProductResponse.ContentAsTypeAsync <ProductResponse>(); model.ExistentProductId = existentProduct.Id; } HttpResponseMessage reponse = await PostAsync("auctions", model.MapToRequest()); if (!reponse.IsSuccessStatusCode) { TempData["AuctionErrorMessage"] = await reponse.Content.ReadAsStringAsync(); return(RedirectToAction(nameof(Create))); } var auction = await reponse.ContentAsTypeAsync <AuctionResponse>(); return(RedirectToAction(nameof(Details), new { id = auction.Id })); }
public async Task <IActionResult> Create() { HttpResponseMessage existentProductsResponse = await GetAsync($"products/forUser/{User.FindFirst(ClaimTypes.NameIdentifier)?.Value}"); HttpResponseMessage categoriesResponse = await GetAsync("categories"); if (!existentProductsResponse.IsSuccessStatusCode) { TempData["AuctionErrorMessage"] = await existentProductsResponse.Content.ReadAsStringAsync(); return(RedirectToAction(nameof(Index))); } if (!categoriesResponse.IsSuccessStatusCode) { TempData["CategoriesErrorMessage"] = await categoriesResponse.Content.ReadAsStringAsync(); return(RedirectToAction(nameof(Index))); } var existentProducts = await existentProductsResponse.ContentAsTypeAsync <IEnumerable <ProductResponse> >(); var categories = await categoriesResponse.ContentAsTypeAsync <IEnumerable <CategoryResponse> >(); var vm = new AuctionCreateViewModel { Categories = categories.MapToViewModel(), ExistentProducts = existentProducts.MapToViewModel() }; return(View(vm)); }
public ActionResult Save(AuctionCreateViewModel vm) { ServiceResult result = _auctionService.AddAuction(vm); if (result.Success) { return(RedirectToAction("SendRegistrationEmail", result)); } return(RedirectToAction("Create")); }
public static AuctionRequest MapToRequest(this AuctionCreateViewModel model) { if (model is null) { throw new ArgumentNullException(nameof(model)); } return(new AuctionRequest { DaysActive = model.DaysActive, ProductId = model.ExistentProductId, StartDate = model.StartDate, StartingPrice = model.StartingPrice }); }
public async Task <ActionResult> Create() { var categories = await AuctionFacade.GetAllCategories(); var model = new AuctionCreateViewModel(); model.CategoriesSelectList = new List <SelectListItem>(); foreach (var category in categories) { model.CategoriesSelectList.Add(new SelectListItem { Text = category.Name, Value = category.Id.ToString() }); } return(View("AuctionCreateView", model)); }
public async Task <ActionResult> Create(AuctionCreateViewModel auctionViewModel) { var account = await AccountFacade.GetAccountAccordingToEmailAsync(auctionViewModel.AccountEmail); var category = await AuctionFacade.GetCategoryAsync(new Guid(auctionViewModel.CategoryId)); var auctionDto = new AuctionDTO() { ClosingTime = auctionViewModel.ClosingTime, ActualPrice = auctionViewModel.ActualPrice, Name = auctionViewModel.Name, Description = auctionViewModel.Description, AccountId = account.Id, IsOpened = true }; await AuctionFacade.CreateAuctionWithCategoryNameAsync(auctionDto, category.Name); return(RedirectToAction("Index", "Home")); }
private AuctionCreateViewModel StripStringsAuctionCreate(AuctionCreateViewModel vm) { vm.Auction.ItemName = Utilities.RemoveSpecialCharacters(vm.Auction.ItemName); return(vm); }