public ActionResult Detail(long id) { Category category = categoryDao.GetById(id); if (category == null) { return(RedirectToAction("Index", "Error")); } return(View(category)); }
public ActionResult Edit(long id) { var dao = new CategoryDao(); var model = dao.GetById(id); return(View(model)); }
public ActionResult Add(Product product, HttpPostedFileBase picture, int countryId, int categoryId) { if (ModelState.IsValid) { if (picture != null) { if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; if (image.Height > 200 || image.Width > 200) { Image smallImage = ImageHelper.ScaleImage(image, 200, 200); Bitmap b = new Bitmap(smallImage); b.Save(Server.MapPath("~/uploads/product/" + imageName), System.Drawing.Imaging.ImageFormat.Jpeg); smallImage.Dispose(); b.Dispose(); product.Image = imageName; } else { picture.SaveAs(Server.MapPath("~/uploads/product") + picture.FileName); } } ; } CategoryDao categoryDao = new CategoryDao(); Category category = categoryDao.GetById(categoryId); product.Category = category; CountryDao countryDao = new CountryDao(); Country country = countryDao.GetById(countryId); product.Country = country; ProductDao productDao = new ProductDao(); productDao.Create(product); TempData["message-success"] = "Kniha byla uspesne pridana"; } else { return(View("Create", product)); } return(RedirectToAction("Index", "Home")); }
public FrmCategory(bool isCansave = true, Guid?id = null) { InitializeComponent(); if (id != null) { //*Note categoryID = (Guid)id; CategoryEntity categoryEntity = new CategoryEntity(); categoryEntity = CategoryDao.GetById(id); this.Text = this.Text + categoryID; txtName.Text = categoryEntity.CategoryName; txtOther.Text = categoryEntity.Other; } btnSaveClose.Enabled = btnSaveNew.Enabled = isCansave; }
public ActionResult Update(Product product, HttpPostedFileBase picture, int categoryId, int availability, int pricePerUnit, int countryId) { ProductDao productDao = new ProductDao(); CategoryDao categoryDao = new CategoryDao(); CountryDao countryDao = new CountryDao(); if (picture != null) { if (picture.ContentType == "image/jpeg" || picture.ContentType == "image/png") { Image image = Image.FromStream(picture.InputStream); Guid guid = Guid.NewGuid(); string imageName = guid.ToString() + ".jpg"; if (image.Height > 200 || image.Width > 200) { Image smallImage = ImageHelper.ScaleImage(image, 200, 200); Bitmap b = new Bitmap(smallImage); b.Save(Server.MapPath("~/uploads/product/" + imageName), System.Drawing.Imaging.ImageFormat.Jpeg); smallImage.Dispose(); b.Dispose(); product.Image = imageName; } else { picture.SaveAs(Server.MapPath("~/uploads/product") + picture.FileName); } } ; } product.Availability = availability; product.PricePerUnit = pricePerUnit; product.Category = categoryDao.GetById(categoryId); product.Country = countryDao.GetById(countryId); productDao.Update(product); TempData["message-success"] = "Produkt byl uspesne upraven"; return(RedirectToAction("Index", "Home")); }
public Category GetById(int id) { return(_dao.GetById(id)); }