public ActionResult AddAddress(AddressModel model) { var customer = workContext.GetAuthenticatedCustomer(); if (customer == null) { return(RedirectToAction("SingIn", "Login")); } Address address = new Address(); address.FirsName = model.FirsName; address.LastName = model.LastName; address.ProvinceId = model.ProvinceId; address.CountiesId = model.CountiesId; address.Email = model.Email; address.Phone = model.Phone; address.Address1 = model.Address; address.CreatedOnUtc = DateTime.Now; db.Addresses.Add(address); if (db.SaveChanges() > 0) { var addressId = db.Addresses.Max(x => x.Id); CustomerAddressMapping cam = new CustomerAddressMapping(); cam.AddressId = addressId; cam.CustomerId = customer.Id; db.CustomerAddressMappings.Add(cam); db.SaveChanges(); } return(RedirectToAction("AddressList", "Customer")); }
public ActionResult Add(CategoryModel model) { Category category = new Category(); category.Name = model.Name; category.Published = model.Published; category.CreatedOnUtc = DateTime.Now; db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult Add(ManufacturerModel manufacturer) { Manufacturer model = new Manufacturer(); model.Name = manufacturer.Name; model.Published = manufacturer.Published; model.CreatedOnUtc = DateTime.Now; model.Deleted = false; db.Manufacturers.Add(model); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult Add(CustomerModel model) { Customer c = new Customer(); c.FirstName = model.FirstName; c.LastName = model.LastName; c.Email = model.Email; c.Active = model.Active; c.CreatedOnUtc = DateTime.Now; c.Password = model.Password; db.Customers.Add(c); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult Add(ProductModel model) { Product p = new Product(); p.Name = model.Name; p.Price = model.Price; p.Sku = model.Sku; p.Active = model.Active; p.Barcode = model.Barcode; p.CategoryId = model.CategoryId; p.ManufacturerId = model.ManufactureId; p.CreatedOnUtc = DateTime.Now; p.Description = model.Description; db.Products.Add(p); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult Add(ProductModel model, HttpPostedFileBase uploadfile) { string filePath = ""; if (uploadfile.ContentLength > 0 && uploadfile != null) { string ext = Path.GetExtension(uploadfile.FileName); filePath = Guid.NewGuid().ToString().Replace("-", "") + "_" + Path.GetFileName(uploadfile.FileName); if (ext == ".jpg" || ext == ".png") { string path = Server.MapPath("~/Theme/images/upload/" + filePath); uploadfile.SaveAs(path); } else { ViewBag.result = "Lütfen .jpg,.png tipinde resim yükleyiniz!"; return(View(model)); } } Product p = new Product(); p.Name = model.Name; p.Price = model.Price; p.Sku = model.Sku; p.Active = model.Active; p.Barcode = model.Barcode; p.CategoryId = model.CategoryId; p.ManufacturerId = model.ManufactureId; p.CreatedOnUtc = DateTime.Now; p.Description = model.Description; p.Photo = filePath; db.Products.Add(p); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult AddProductToCart(int quantity, int productId) { var customer = workContext.GetAuthenticatedCustomer(); if (customer == null) { TempData["result"] = "Giriş Yapınız!"; return(RedirectToAction("ProductDetail", "Product", new { id = productId })); } var ShoppingCarts = db.ShoppingCartItems.FirstOrDefault(x => x.CustomerId == customer.Id && x.ProductId == productId); if (ShoppingCarts == null) { ShoppingCartItem sci = new ShoppingCartItem(); sci.CustomerId = customer.Id; sci.ProductId = productId; sci.Quantity = quantity; sci.CreatedOnUtc = DateTime.Now; db.ShoppingCartItems.Add(sci); if (db.SaveChanges() > 0) { TempData["result"] = "Sepete Eklendi."; } else { TempData["result"] = "Ekleme işleminde sorun oluştu"; } } else { ShoppingCarts.Quantity += quantity; if (db.SaveChanges() > 0) { TempData["result"] = "Sepete Güncellendi."; } else { TempData["result"] = "Sepet güncelleme işleminde sorun oluştu"; } } return(RedirectToAction("ProductDetail", "Product", new { id = productId })); }
public ActionResult Create(AddressCheckModel model) { var customer = workContext.GetAuthenticatedCustomer(); if (customer == null) { return(RedirectToAction("SingIn", "Login")); } #region ShoppingCart var cartList = db.ShoppingCartItems.Where(x => x.CustomerId == customer.Id).ToList(); decimal?totalprice = 0; foreach (var item in cartList) { var product = db.Products.FirstOrDefault(x => x.Id == item.ProductId); var ShoppingCart = new ShoppingCartModel(); ShoppingCart.Id = item.Id; ShoppingCart.Quantity = item.Quantity; ShoppingCart.ProductId = product.Id; ShoppingCart.Price = product.Price; ShoppingCart.CustomerId = item.CustomerId; totalprice += product.Price * item.Quantity; model.ShoppingCarts.Add(ShoppingCart); } #endregion #region OrderCerate Order order = new Order(); order.CustomerId = customer.Id; order.AddressId = model.AddressId; order.ShippingMethod = model.Cargo; order.OrderStatusId = (int)OrderStatusEnum.Preparing; order.ShippingStatusId = (int)ShippingStatusEnum.NotYetShipped; order.OrderTotal = totalprice; order.Deleted = false; order.CreatedOnUtc = DateTime.Now; db.Orders.Add(order); if (db.SaveChanges() > 0) { foreach (var product in model.ShoppingCarts) { OrderItem oi = new OrderItem(); oi.OrderId = order.Id; oi.ProductId = product.ProductId; oi.Quantity = product.Quantity; oi.Price = product.Price; db.OrderItems.Add(oi); if (db.SaveChanges() > 0) { var cart = db.ShoppingCartItems.SingleOrDefault(x => x.Id == product.Id && x.CustomerId == customer.Id); if (cart != null) { db.ShoppingCartItems.Remove(cart); db.SaveChanges(); } } } } #endregion return(RedirectToAction("Index", "Home")); }