public ActionResult Checkout(List <Checkout> obj) { List <ShoppingCart> lstCart = new List <ShoppingCart>(); using (ECommerce product = new ECommerce()) { using (var transaction = product.Database.BeginTransaction()) { try { if (obj != null) { foreach (Checkout item in obj) { ShoppingCart cart = new ShoppingCart(); //DateTime localDate = DateTime.Now; cart.CartId = item.CartId; cart.ProductName = item.ProductName; cart.Quantity = item.Quantity; decimal total = (item.Quantity * Convert.ToDecimal(item.Productprice)); cart.TotalAmount = total; cart.OrderDate = DateTime.Now; product.ShoppingCarts.Add(cart); product.SaveChanges(); //lstCart.Add(cart); } Order order = new Order(); order.CustomerID = Convert.ToInt32(Session["CustomerID"]); order.OrderDate = DateTime.Now; product.Orders.Add(order); product.SaveChanges(); } } catch (Exception ex) { transaction.Rollback(); } transaction.Commit(); } } var urlBuilder = new UrlHelper(Request.RequestContext); var url = urlBuilder.Action("Welcome", "Customers"); return(Json(new { status = "success", redirectUrl = url })); //return RedirectToAction("Welcome", "Customers"); //return View("~/Views/Customers/Welcome.cshtml"); //return View("~/Views/ShoppingCart/Cart.cshtml"); }
public ActionResult Create([Bind(Include = "CustomerName,State,Address,ContactNumber,email,CustomerPassword")] Customer customer) { if (ModelState.IsValid) { //customer.CustomerID++; ; // db.ExecuteCommand("SET IDENTITY_INSERT MyTable ON"); db.Customers.Add(customer); db.SaveChanges(); //id = customer.CustomerID; //id++; return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Customer_Destroy([DataSourceRequest] DataSourceRequest request, Customer customer) { if (customer != null) { using (var db = new ECommerce()) { // Create a new Customer entity and set its properties from the posted Customer model. var entity = new Customer { CustomerID = customer.CustomerID, CustomerName = customer.CustomerName, CustomerPassword = customer.CustomerPassword, Address = customer.Address, State = customer.State, Role = customer.Role, ContactNumber = customer.ContactNumber }; // Attach the entity. db.Customers.Attach(entity); // Delete the entity. db.Customers.Remove(entity); // Delete the entity in the database. db.SaveChanges(); } } // Return after removed Customer. Also return any validation errors. return(Json(new[] { customer }.ToDataSourceResult(request, ModelState))); }
public ActionResult Customer_Update([DataSourceRequest] DataSourceRequest request, Customer customer) { //if (ModelState.IsValid) if (customer != null) { using (ECommerce db = new ECommerce()) { var entity = new Customer() { CustomerID = customer.CustomerID, CustomerPassword = customer.CustomerPassword, email = customer.email, CustomerName = customer.CustomerName, State = customer.State, Address = customer.Address, ContactNumber = customer.ContactNumber, Role = customer.Role }; db.Customers.Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } } return(Json(new[] { customer }.ToDataSourceResult(request, ModelState))); }
public ActionResult Cart(ProdutViewModel model, FormCollection form) { var productId = Convert.ToInt16(form["productId"]); var quantity = Convert.ToInt16(form["Quantity"]); ShoppingCart cart = new ShoppingCart(); //Order order = new Order(); try { ProductInfo objProductDetails = new ProductInfo(); ////Customer customer = new Customer(); using (ECommerce objEntity = new ECommerce()) { objProductDetails = objEntity.ProductInfoes.Where(p => p.ProductID == productId).FirstOrDefault(); if (objProductDetails != null) { cart.ProductName = objProductDetails.ProductName; cart.Quantity = quantity; decimal v = (quantity * objProductDetails.ProductPrice); cart.TotalAmount = v; objEntity.ShoppingCarts.Add(cart); objEntity.SaveChanges(); //Store cart products in cookie// //HttpCookie cookies = new HttpCookie("Product"); //cookies["Product"] = JsonConvert.SerializeObject(cart); } } } catch (Exception ex) { Console.WriteLine("Product cannot be added in cart at this time:", ex); } return(View()); //return View("~/Views/ShoppingCart/Cart.cshtml"); }
public ActionResult Employee_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Employee> emps) { db.Configuration.LazyLoadingEnabled = false; //db.Configuration.ProxyCreationEnabled = false; if (emps != null) { foreach (var emp in emps) { //var isIn = db.Employees.Where(s => s.EmpID.Equals(emp.Manager) && s.Manager.Equals(emp.EmpID)); //var custEmpQuery = result.Where(c => c.Manager.Equals(emp.EmpID)); //var isIn = result.Where(c => c.Manager.Equals(emp.EmpID)); //bool isIn = result.Any(c => c.Manager.Equals(emp.EmpID)); var result = MangerList(emp.EmpID); var a = emp.Manager; if (!result.Any(s => s.EmpID.Equals(a)) && !emp.EmpID.Equals(emp.Manager)) { using (ECommerce db = new ECommerce()) { var entity = new Employee() { EmpID = emp.EmpID, EmployeeName = emp.EmployeeName, Manager = emp.Manager }; db.Employees.Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } return(Json(emps.ToDataSourceResult(request, ModelState))); } } } return(RedirectToAction("Employee_Read")); }
public ActionResult Employee_Destroy([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Employee> emps) { if (emps != null) { foreach (var emp in emps) { using (var db = new ECommerce()) { // Create a new Employee entity and set its properties from the posted employee model. var entity = new Employee { EmpID = emp.EmpID, EmployeeName = emp.EmployeeName, //ManagerName = emp.ManagerName, Manager = emp.Manager }; // Attach the entity. db.Employees.Attach(entity); // Delete the entity. db.Employees.Remove(entity); // Delete the entity in the database. db.SaveChanges(); } } } return(Json(emps.ToDataSourceResult(request, ModelState))); //return Json(new[] { emps }.ToDataSourceResult(request, ModelState)); }
public ActionResult Customer_Create([DataSourceRequest] DataSourceRequest request, Customer customer) { if (customer != null) { db.Customers.Add(customer); db.SaveChanges(); } return(Json(new[] { customer }.ToDataSourceResult(request, ModelState))); }
public ActionResult Employee_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <Employee> emps) { db.Configuration.LazyLoadingEnabled = false; //db.Configuration.ProxyCreationEnabled = false; var results = new List <Employee>(); if (emps != null) { foreach (var emp in emps) { var manager = db.Employees.Add(emp); db.SaveChanges(); results.Add(emp); } } return(Json(results.ToDataSourceResult(request, ModelState))); //return Json(new[] { results }.ToDataSourceResult(request, ModelState)); }
public IHttpActionResult PutOrdine(int id, Ordine ordine) { log.Debug($"update dell'ordine num. {id}"); if (!ModelState.IsValid) { log.Warn($"modello ordine non valido"); return(BadRequest(ModelState)); } if (id != ordine.NumeroOrdine) { log.Warn($"id ordine non coincidente {id} != {ordine.NumeroOrdine}"); return(BadRequest()); } db.Entry(ordine).State = EntityState.Modified; try { db.SaveChanges(); log.Info($"ordine num. {id} salvato"); } catch (DbUpdateConcurrencyException e) { log.Error($"eccezione salvando ordine num. {id}", e); if (!OrdineExists(id)) { log.Warn($"l'ordine num. {id} non esiste"); return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }