public async Task <IActionResult> Create(OfferCreateInputModel inputModel) { var invalidDate = inputModel.ExpirationDate.Date.CompareTo(DateTime.Now.Date) <= 0; if (!this.ModelState.IsValid || invalidDate) { var categories = await this.categoriesService.GetAllAsync <CategoryDropDownViewModel>(); var suppliers = await this.suppliersService.GetAllAsync <SupplierDropDownViewModel>(); var viewModel = new OfferCreateInputModel { Suppliers = suppliers, Categories = categories, Data = inputModel.Data, ExpirationDate = inputModel.ExpirationDate, }; this.SetInvalidExpirationDateError(invalidDate); return(this.View(viewModel)); } var offerId = await this.offersService .CreateAsync(inputModel.Name, inputModel.SupplierId, inputModel.CategoryId, inputModel.ExpirationDate, inputModel.Data); if (offerId == null) { return(this.RedirectToAction("Error", "Home")); } this.TempData[Notifications.Key] = Notifications.SuccessfullyCreatedOffer; return(this.RedirectToAction("All")); }
public async Task <IActionResult> Create() { var suppliers = await this.suppliersService.GetAllAsync <SupplierDropDownViewModel>(); var categories = await this.categoriesService.GetAllAsync <CategoryDropDownViewModel>(); var viewModel = new OfferCreateInputModel { Suppliers = suppliers, Categories = categories, ExpirationDate = DateTime.Now.Date, }; return(this.View(viewModel)); }
public void Create(OfferCreateInputModel input) { MicroserviceResponse response = Execute( _client.BaseAddress.ToString(), new { input.Name, input.TotalPrice, Products = input.ProductIds, input.Discount, input.ExpiryDate, input.ImageUrl }, HttpMethod.Post); Console.WriteLine(); }
public IActionResult OnPost() { IEnumerable <ProductViewModel> allProducts = (IEnumerable <ProductViewModel>)_sessionHelper.GetItem("AllProducts"); var totalPrice = allProducts .Where(vm => SelectedProductsIds.Contains(vm.Id)) .Sum(p => p.Price); var createOfferInput = new OfferCreateInputModel { Name = Name, ProductIds = SelectedProductsIds.ToArray(), TotalPrice = totalPrice, ImageUrl = ImageUrl, ExpiryDate = ExpiryDate }; _sessionHelper.AddRenewItem("CreateOfferInput", createOfferInput); return(RedirectToPage("./Preview")); }