public IActionResult CreateFromRequest(string id) { RequestToProductViewModel model = this.requestsService.GetSingleRequestToProductById(id); this.AddImagesToModel(model); return(this.View(model)); }
public async Task <IActionResult> CreateFromRequest(RequestToProductViewModel model) { if (!this.ModelState.IsValid) { return(this.View("CreateFromRequest", model)); } await this.productsService.CreateProductFromRequestAsync(model); await this.requestsService.ChangeRequestStatusAsync(model.Id, "Product"); return(this.RedirectToAction("All")); }
public RequestToProductViewModel GetSingleRequestToProductById(string id) { var request = this.requestsRepository.All().FirstOrDefault(x => x.Id == id); var viewModel = new RequestToProductViewModel() { Id = id, Name = request.Name, Type = request.Type.ToString(), Status = request.Status.ToString(), Description = request.Description, MoneyCreationPrice = request.MoneyCreationPrice, DeeCoinsCreationPrice = request.DeeCoinsCreationPrice, TakenById = request.TakenBy, }; return(viewModel); }
public async Task CreateProductFromRequestAsync(RequestToProductViewModel model) { var requestFromDb = this.requestRepository.All().FirstOrDefault(x => x.Id == model.Id); var categoryId = this.categoriesService .GetAllCategories() .FirstOrDefault(x => x.Name == model.Category).Id; var product = new Product() { Name = model.Name, Price = (decimal)model.Price, Description = model.Description, Specification = model.Specification, CreatedById = requestFromDb.TakenBy, Type = requestFromDb.Type, CategoryId = categoryId, }; var images = this.imageRepository.All().Where(x => x.RequestId == model.Id).ToList(); var productImages = new List <ProductImage>(); foreach (var image in images) { var productImage = new ProductImage() { Image = image, Product = product, }; productImages.Add(productImage); } product.ProductImages = productImages; await this.productRepository.AddAsync(product); await this.productRepository.SaveChangesAsync(); }