public void Create(MainImageViewModel model) { foreach (var element in GetAllPerProductId(model.ProductId)) { if (model.MainPicture) { element.MainPicture = false; } else { break; } } Image picture = new Image { ImageId= model.ImageId, ProductId = model.ProductId, FileName = model.FileName, Picture = new byte [model.Image.ContentLength], ImageMineType = model.Image.ContentType, MainPicture = model.MainPicture }; using (MemoryStream memStream = new MemoryStream(model.Image.ContentLength)) { // model.Image.InputStream.Read(picture.Picture,0, model.Image.ContentLength); model.Image.InputStream.CopyTo(memStream, model.Image.ContentLength); picture.Picture = memStream.ToArray(); } using (var context = new WebShopMVCContext()) { context.Images.Add(picture); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new WebShopMVCContext()) { var product = context.Products.Find(id); context.Products.Remove(product); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new WebShopMVCContext()) { context.Clients.Remove( context.Clients.Where(m => m.UserId == id).FirstOrDefault()); context.SaveChanges(); } }
public void RemoveUnit(int productId) { using (var context = new WebShopMVCContext()) { var product = context.CartItems.Find(productId); context.CartItems.Remove(product); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new WebShopMVCContext()) { var picture = context.Images.Find(id); context.Images.Remove(picture); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new WebShopMVCContext()) { var category = context.Categories.Find(id); context.Categories.Remove(category); context.SaveChanges(); } }
public void Create(CategoryViewModel model) { Category category = new Category { CategoryName = model.CategoryName }; using (var context = new WebShopMVCContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public void Create(SubcategoryViewModel model) { Subcategory subcategory = new Subcategory { CategoryId = model.CategoryId, SubcategoryName = model.SubcategoryName }; using (var context = new WebShopMVCContext()) { context.Subcategories.Add(subcategory); context.SaveChanges(); } }
public void AddItem(int clientId, int productId, int quantity) { CartItem item = new CartItem { ProductId = productId, ClientId = clientId, Quantity = quantity }; using (var context = new WebShopMVCContext()) { context.CartItems.Add(item); context.SaveChanges(); } }
public void Create(ProductViewModel model) { Product product = new Product { ProductId = model.ProductId, ProductName = model.ProductName, SubcategoryId = model.SubcategoryId, Price = model.Price, Discount = model.Discount, Description = model.Description }; using (var context = new WebShopMVCContext()) { context.Products.Add(product); context.SaveChanges(); } }
public void Create(ClientViewModel model) { Client client = new Client { FirstName = model.FirstName, LastName = model.LastName, Login = model.Login, Password = model.Password, //.GetHashCode().ToString(), Email = model.Email, Phone = model.Phone }; using (var context = new WebShopMVCContext()) { context.Clients.Add(client); context.SaveChanges(); } }
public void ClearCart() { var list = new List<CartItem>(); using (var context = new WebShopMVCContext()) { list = context.CartItems.Select(m => new CartItem { CartItemId = m.CartItemId, ClientId = m.ClientId, Client = m.Client, ProductId = m.ProductId, Product = m.Product, Quantity = m.Quantity }).ToList(); context.CartItems.RemoveRange(list); context.SaveChanges(); } }
public void Create(EmployeeViewModel model) { Employee employee = new Employee { FirstName = model.FirstName, LastName = model.LastName, Login = model.Login, Password = model.Password, Address = model.Address, Email = model.Email, Phone = model.Phone, Role = model.Role, IsBlocked = model.IsBlocked, IsDelete = model.IsDelete, RowVersion = model.RowVersion }; using (var context = new WebShopMVCContext()) { context.Employees.Add(employee); context.SaveChanges(); } }
public void Update(ProductViewModel model) { using (var context = new WebShopMVCContext()) { var product = context.Products.Find(model.ProductId); product.ProductName = model.ProductName; product.SubcategoryId = model.SubcategoryId; product.Price = model.Price; product.Discount = model.Discount; product.Description = model.Description; context.SaveChanges(); } }
public void Update(EmployeeViewModel model) { using (var context = new WebShopMVCContext()) { var employee = context.Employees.Find(model.UserId); employee.FirstName = model.FirstName; employee.LastName = model.LastName; employee.Address = model.Address; employee.Email = model.Email; employee.Phone = model.Phone; employee.Login = model.Login; employee.Password = model.Password; employee.Role = model.Role; employee.IsBlocked = model.IsBlocked; employee.IsDelete = model.IsDelete; employee.RowVersion = model.RowVersion; context.SaveChanges(); } }
public void Update(CategoryViewModel model) { using (var context = new WebShopMVCContext()) { var category = context.Categories.Find(model.CategoryId); category.CategoryName = model.CategoryName; context.SaveChanges(); } }