public ActionResult UpdateOrAddProduct(EditAddProductViewModel data, HttpPostedFileBase file) { if (data.Product.ProductID == 0) { if (file != null && file.ContentLength > 0) { if (ModelState.IsValid) { // Generate filename var fileExt = Path.GetExtension(file.FileName); var filename = Guid.NewGuid() + fileExt; var path = Path.Combine(Server.MapPath("~/Content/Products/"), filename); file.SaveAs(path); // Save to DB data.Product.FileNamePhoto = filename; data.Product.AddDate = DateTime.Now; db.Entry(data.Product).State = EntityState.Added; db.SaveChanges(); return(RedirectToAction("UpdateOrAddProduct", new { responseSuccess = true })); } else { var category = db.Categories.ToArray(); data.Categories = category; return(View(data)); } } else { ModelState.AddModelError("", "Nie wskazano pliku."); var category = db.Categories.ToArray(); data.Categories = category; return(View(data)); } } else { if (data.Product.Price == 0 || data.Product.Weight == 0) { return(RedirectToAction("UpdateOrAddProduct", new { responseError = true })); } else { db.Entry(data.Product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("UpdateOrAddProduct", new { responseSuccess = true })); } } }
public ActionResult Edit([Bind(Include = "ContactID,Name,Email,Phone,Message,SentAnswer")] Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); // return RedirectToAction("Index", new { state = contact.SentAnswer }); return(RedirectToAction("Index", "Manage")); } return(View(contact)); }
public ActionResult Report() { string id = Request.Form["id"]; string trId = Request.Form["tr_id"]; string trDate = Request.Form["tr_date"]; string trCRC = Request.Form["tr_crc"]; string trAmount = Request.Form["tr_amount"]; string trPaid = Request.Form["tr_paid"]; string trDesc = Request.Form["tr_desc"]; string trStatus = Request.Form["tr_status"]; string trError = Request.Form["tr_error"]; string trEmail = Request.Form["tr_email"]; string md5Sum = Request.Form["md5sum"]; if (!ContainsNullOrEmptyString(id, trId, trDate, trAmount, trCRC)) { Response.Write("TRUE"); bool isSuccessful = IsValid(md5Sum, trId, trAmount, trCRC); if (isSuccessful == true) { logger.Info("Wykonano prawidłowo płatność"); int OrderID = Int32.Parse(trCRC); Order order = db.Orders.SingleOrDefault(a => a.OrderID == OrderID); this.mailService.SendCompletedOrderEmail(order); order.PaymentState = true; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } else { logger.Info("Nie wykonano prawidłowo płatności"); } } return(View()); }