public void AddProduct(IFormCollection data) { var files = data.Files.ToList(); var product = JsonConvert.DeserializeObject <Product>(data["product"]); var path = Path.Combine(Directory.GetCurrentDirectory(), "ClientApp", "build", "product", product.Url); if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); int countOfFiles = 0; for (var i = 0; i < files.Count; i++) { if (files[i].Length > 0) { using (var stream = new FileStream(path + "/" + product.Url + i + ".jpg", FileMode.Create)) { files[i].CopyTo(stream); } countOfFiles++; } } Guid new_guid = Guid.NewGuid(); product.Id = new_guid; product.CountImages = countOfFiles; _repo.AddProduct(product); }
public HttpResponseMessage Post([FromBody] Product product) { if (_repo.AddProduct(product) && _repo.Save()) { return(Request.CreateResponse(HttpStatusCode.Created, product)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public ActionResult InsertProduct(Product product) { if (_repo.AddProduct(product) && _repo.Save()) { return(RedirectToAction("Index")); } return(View(product)); }
public string CloseGroupFor(string productName) { var groupName = repo.GetGroupByExactProductName(productName); if (groupName != null) { return(groupName); } var words = productNameProcessor.Process(productName); var groupMap = new Dictionary <Group, int>(); foreach (var group in repo.List()) { groupMap[group] = CalcProductWeight(group, words); } var best = groupMap.First(); foreach (var pair in groupMap.Skip(1)) { if (best.Value < pair.Value) { best = pair; } } if (best.Value > 0) { if (needAddNewProducts) { repo.AddProduct(best.Key, productName); } return(best.Key.Name); } throw new Exception($"Не удалось определить группу для {productName}"); }