public void Delete(int categoryId) { using (var context = new HardwareShopContext()) { var category = this.GetCategoryById(categoryId, context); category.IsDeleted = true; context.SubCategories.Where(sc => sc.CategoryId == category.CategoryId).Update(c => new SubCategory { IsDeleted = true }); context.Items.Where(i => i.SubCategory.CategoryId == category.CategoryId).Update(i => new Item { IsDeleted = true }); context.Reviews.Where(r => r.Item.SubCategory.CategoryId == category.CategoryId).Update(r => new Review { IsDeleted = true }); context.Comments.Where(c => c.Review.Item.SubCategory.CategoryId == category.CategoryId).Update(c => new Comment { IsDeleted = true }); context.Entry(category).State = EntityState.Modified; context.SaveChanges(); } }
public bool IsItemDeleted(int itemId) { using (var context = new HardwareShopContext()) { return(context.Items.Any(i => i.ItemId == itemId && i.IsDeleted == false)); } }
public Item GetItem(int itemId) { using (var context = new HardwareShopContext()) { return(context.Items.Find(itemId)); } }
public IPagedList <ItemViewModel> GetDeletedItems(string queryString, int?page) { using (var context = new HardwareShopContext()) { var items = new List <Item>(); if (queryString != null) { items = context.Items .Where(i => i.IsDeleted == true && (i.ManufacturerName.Contains(queryString) || i.Description.Contains(queryString) || i.Model.Contains(queryString))) .OrderByDescending(i => i.UploadDate) .ToList(); } else { items = context.Items .Where(i => i.IsDeleted == true) .OrderByDescending(i => i.UploadDate) .ToList(); } var viewModels = Mapper.Map <IEnumerable <Item>, IEnumerable <ItemViewModel> >(items); return(viewModels.ToPagedList(page ?? 1, 3)); } }
public bool IsItemExisting(int itemId) { using (var context = new HardwareShopContext()) { return(context.Items.Any(i => i.ItemId == itemId)); } }
public ApplicationUser GetUser(string userId) { using (var context = new HardwareShopContext()) { return(this.GetUserById(userId, context)); } }
public void EditItem(EditItemViewModel model) { using (var context = new HardwareShopContext()) { var item = this.GetItemById(model.ItemId, context); item.SubCategoryId = model.SubCategoryId; item.Description = model.Description; item.Quantity = model.Quantity; item.Price = model.Price; item.NewPrice = model.NewPrice; item.Model = model.Model; item.ItemStatus = model.ItemStatus; item.ManufacturerName = model.ManufacturerName; item.WarrantyLengthMonths = model.WarrantyLengthMonths; if (model.PictureBase != null) { MemoryStream stream = new MemoryStream(); model.PictureBase.InputStream.CopyTo(stream); byte[] pictureInData = stream.ToArray(); item.Picture = pictureInData; } context.SaveChanges(); } }
public void CreateNewSale(string userId, CreateSaleViewModel model) { using (var context = new HardwareShopContext()) { var user = context.Users.FirstOrDefault(u => u.Id == userId); var cart = context.Carts.FirstOrDefault(c => c.UserId == userId && c.IsSold == false); var sale = Mapper.Instance.Map <CreateSaleViewModel, Sale>(model); sale.Cart = cart; sale.SaleDate = DateTime.Now; sale.TotalPrice = cart.Items.Sum(i => i.Price); cart.IsSold = true; foreach (var item in cart.Items) { item.Quantity--; } user.Carts.Add(new Cart()); context.Sales.Add(sale); context.SaveChanges(); context.Items.Where(i => i.Quantity < 1).Update(i => new Item { ItemStatus = ItemStatus.OutOfStock }); context.SaveChanges(); } }
public IList <string> GetRoles() { using (var context = new HardwareShopContext()) { return(context.Roles.Select(r => r.Name).OrderBy(r => r).ToList()); } }
public decimal GetTotalPrice(string userId) { using (var context = new HardwareShopContext()) { return(context.Carts.FirstOrDefault(s => s.UserId == userId && s.IsSold == false).TotalPrice); } }
public bool IsReviewDeleted(int reviewId) { using (var context = new HardwareShopContext()) { return(context.Reviews.Any(r => r.ReviewId == reviewId && r.IsDeleted == false)); } }
public void ClearItemsFromCart(string userId) { using (var context = new HardwareShopContext()) { context.Carts.FirstOrDefault(s => s.UserId == userId && s.IsSold == false).Items.Clear(); context.SaveChanges(); } }
private ApplicationUser GetAllUserInfo(string userId, HardwareShopContext context) { return(context.Users .Where(u => u.Id == userId) .Include(u => u.Reviews) .Include(u => u.Comments) .FirstOrDefault()); }
public CategoryViewModel GetCategory(int categoryId) { using (var context = new HardwareShopContext()) { var category = this.GetCategoryById(categoryId, context); var viewModel = Mapper.Map <CategoryViewModel>(category); return(viewModel); } }
public EditUserViewModel GetUserForEdit(string userId) { using (var context = new HardwareShopContext()) { var user = this.GetUserById(userId, context); var model = Mapper.Map <EditUserViewModel>(user); return(model); } }
public DeleteReviewViewModel GetReviewForDelete(int reviewId) { using (var context = new HardwareShopContext()) { var review = this.GetReviewById(reviewId, context); var model = Mapper.Map <DeleteReviewViewModel>(review); return(model); } }
public void Restore(int subCategoryId) { using (var context = new HardwareShopContext()) { var subCategory = this.GetSubCategoryById(subCategoryId, context); subCategory.IsDeleted = false; context.SaveChanges(); } }
public ManageUserViewModel GetUser(string id) { using (var context = new HardwareShopContext()) { var user = this.GetUserByUsername(id, context); var model = Mapper.Map <ManageUserViewModel>(user); return(model); } }
public SaleDetailsViewModel GetSale(int saleId) { using (var context = new HardwareShopContext()) { Sale sale = context.Sales.FirstOrDefault(s => s.SaleId == saleId); SaleDetailsViewModel model = Mapper.Instance.Map <Sale, SaleDetailsViewModel>(sale); return(model); } }
public IEnumerable <EditSubCategoryViewModel> GetAllSubCategories() { using (var context = new HardwareShopContext()) { var subCategories = context.SubCategories; var viewModels = Mapper.Map <IEnumerable <SubCategory>, IEnumerable <EditSubCategoryViewModel> >(subCategories); return(viewModels); } }
public void AddItem(CreateItemViewModel model) { using (var context = new HardwareShopContext()) { var newItem = Mapper.Map <Item>(model); context.Items.Add(newItem); context.SaveChanges(); } }
public IEnumerable <CategoryViewModel> GetAllCategories() { using (var context = new HardwareShopContext()) { var categories = context.Categories.ToList(); var viewModels = Mapper.Map <IEnumerable <Category>, IEnumerable <CategoryViewModel> >(categories); return(viewModels); } }
public void AddCategory(CategoryViewModel model) { using (var context = new HardwareShopContext()) { var newCategory = Mapper.Map <Category>(model); context.Categories.Add(newCategory); context.SaveChanges(); } }
public void DeleteComment(int commentId) { using (var context = new HardwareShopContext()) { var comment = GetCommentById(commentId, context); comment.IsDeleted = true; context.SaveChanges(); } }
public void AddSubCategory(EditSubCategoryViewModel model) { using (var context = new HardwareShopContext()) { var subCategory = Mapper.Map <SubCategory>(model); context.SubCategories.Add(subCategory); context.SaveChanges(); } }
public IEnumerable <NavbarCategoriesViewModel> GetCategories() { using (var context = new HardwareShopContext()) { var categories = context.Categories.Where(c => c.IsDeleted == false).ToList(); var model = Mapper.Map <IEnumerable <Category>, IEnumerable <NavbarCategoriesViewModel> >(categories); return(model); } }
public void EditComment(CommentViewModel model) { using (var context = new HardwareShopContext()) { var comment = this.GetCommentById(model.CommentId, context); comment.Content = model.Content; context.SaveChanges(); } }
public IEnumerable <HomeItemsViewModel> GetItemsBySubCategoryId(int?page, int subCategoryId) { using (var context = new HardwareShopContext()) { var items = context.Items.Where(i => i.SubCategoryId == subCategoryId && i.IsDeleted == false).ToList(); var model = Mapper.Map <IEnumerable <Item>, IEnumerable <HomeItemsViewModel> >(items).OrderByDescending(i => i.UploadDate); return(model.ToPagedList(page ?? 1, 3)); } }
public DeleteCommentViewModel GetCommentForDelete(int commentId) { using (var context = new HardwareShopContext()) { var comment = this.GetCommentById(commentId, context); var model = Mapper.Map <DeleteCommentViewModel>(comment); return(model); } }
public DetailsItemViewModel GetItemDetailsById(int?itemId) { using (var context = new HardwareShopContext()) { Item item = this.GetItemById(itemId, context); DetailsItemViewModel model = Mapper.Instance.Map <Item, DetailsItemViewModel>(item); return(model); } }