public Sku() { brand=new Brand(); smalPhoto=new Photo(); listPhoto=new List<PhotoBig>(); listCategory=new List<Category>(); listSpecification=new List<Specification>(); listComment = new List<Comment>(); }
public bool AddSmalPhotoToSKU(long id, Photo photo) { var result = false; try { dbService.Run(db => { var SkuDB = db.GetRepository<Sku>().TryOne(id); if (SkuDB != null) { SkuDB.smalPhoto = photo; db.GetRepository<Sku>().Update(SkuDB); result = true; } }); } catch (Exception err) { result = false; logger.Error(err.Message); } return result; }
public ActionResult UploadSmalPhoto(long id, HttpPostedFileBase smalPhotoFile) { try { if (smalPhotoFile != null) { if (smalPhotoFile.ContentLength > 0) { var path = UploadPhoto(id, smalPhotoFile); if (!string.IsNullOrEmpty(path)) { var pho=new Photo(){name = string.Empty, path = path, skuId = id}; if (dataService.AddSmalPhotoToSKU(id, pho)) { return RedirectToAction("SkuData", "Admin", new {id=id}); } } } } else { return Content("Фото НЕ сохранено ", "text/html"); } } catch (Exception err) { Response.StatusCode = (int) HttpStatusCode.BadRequest; return Content("Фото НЕ сохранено " + err, "text/html"); } return RedirectToAction("SkuData", "Admin", new { id = id }); }