public ActionResult Create(FormCollection collection, HttpPostedFileBase fileUpload, HttpPostedFileBase previewFileUpload) { using (var context = new SiteContainer()) { if (fileUpload != null && previewFileUpload != null) { var product = new Product(); TryUpdateModel(product, new[] { "SortOrder" }); product.Description = HttpUtility.HtmlDecode(collection["Description"]); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", fileUpload.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, fileUpload, 500); product.ImageSource = fileName; fileName = IOHelper.GetUniqueFileName("~/Content/Images", previewFileUpload.FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, previewFileUpload, 500); product.PreviewImageSource = fileName; context.AddToProduct(product); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); } }
public ActionResult Order(FormCollection form) { using (var context = new SiteContainer()) { var order = new Order {Date = DateTime.Now}; TryUpdateModel(order, new[] {"ProductId", "ProductImageSource", "Name", "Email", "Phone", "Description","Size"}); context.AddToOrder(order); context.SaveChanges(); string defaultMailAddressFrom = ConfigurationManager.AppSettings["feedbackEmailFrom"]; string defaultMailAddresses = ConfigurationManager.AppSettings["feedbackEmailsTo"]; var emailFrom = new MailAddress(defaultMailAddressFrom, "Студия Евгения Миллера"); var emailsTo = defaultMailAddresses .Split(new[] { ";", " ", "," }, StringSplitOptions.RemoveEmptyEntries) .Select(s => new MailAddress(s)) .ToList(); var result = Helpers.MailHelper.SendTemplate(emailFrom, emailsTo, "Я - Эго. Форма заказа", "FeedbackTemplate.htm", null, true, form["Name"], form["Email"], form["ProductId"], form["Phone"],order.Id); return RedirectToAction("Index", "Home", new {id = "gallery"}); } }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var order = context.Order.First(o => o.Id == id); context.DeleteObject(order); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Edit(int id, FormCollection collection) { using (var context = new SiteContainer()) { var content = context.Content.First(c => c.Id == id); TryUpdateModel(content, new[] {"Title","Sortorder","SeoDescription","SeoKeywords","MainPage"}); content.Text = HttpUtility.HtmlDecode(collection["Text"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area="", id = content.Name }); } }
public ActionResult CustomCreate(FormCollection form, HttpPostedFileBase files) { using (var context = new SiteContainer()) { if (files!=null) { var product = new Product(); TryUpdateModel(product, new[] { "SortOrder"}); product.Description = HttpUtility.HtmlDecode(form["Description"]); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", files.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); GraphicsHelper.SaveOriginalImage(filePath, fileName, files, 1200); product.ImageSource = fileName; fileName = IOHelper.GetUniqueFileName("~/Content/Images", files.FileName); filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); int x1 = Convert.ToInt32(form["x1"]); int y1 = Convert.ToInt32(form["y1"]); int w = Convert.ToInt32(form["w"]); int h = Convert.ToInt32(form["h"]); GraphicsHelper.SaveCropPreview(filePath, fileName, files, x1, y1, w, h); product.PreviewImageSource = fileName; context.AddToProduct(product); context.SaveChanges(); } } return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var product = context.Product.First(p => p.Id == id); ImageHelper.DeleteImage(product.ImageSource); ImageHelper.DeleteImage(product.PreviewImageSource); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); } }
public ActionResult Edit(int id, FormCollection collection) { using (var context = new SiteContainer()) { var product = context.Product.First(p => p.Id == id); TryUpdateModel(product, new[] { "SortOrder" }); product.Description = HttpUtility.HtmlDecode(collection["Description"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "gallery" }); } }