public bool Add(UserProduct userProduct) { var userId = _uSERRepository.FindBy(userProduct.UserId); if (userProduct == null) { return(false); } return(_userProductRepository.Add(userProduct) > 0); }
public IActionResult AddProduct([FromBody] AddProductViewModel model) { try { string userId = User.GetUserIdToken(); if (ModelState.IsValid) { UserProduct userProduct = new UserProduct() { Name = model.Name, UserId = userId, ProductId = model.ProductId, Condition = model.Condition, Description = model.Description, Price = model.Price, IsNegotiable = model.IsNegotiable, IsReplacable = model.IsReplacable, DateAdded = DateTime.Now }; foreach (var item in model.Images) { userProduct.UserProductImages.Add(new UserProductImages() { Images = SaveAnImages(item) }); } _userProductRepository.Add(userProduct); _userProductRepository.SaveAll(); return(Ok(new { message = "Product Successfully Added." })); } return(BadRequest("The Product Information is not valid.")); } catch { return(BadRequest("An Error Has Occured.")); } }