public JsonResult SaveCategory(Category category) { string message = ""; bool savedSuccessfully = true; try { if (category != null) { if (category.ProductCategoryId > 0) { CategoryDbModel.UpdateCategory(category); message = "Category updated successfully"; } else { CategoryDbModel.SaveCategory(category); message = "Category created successfully"; } } else { message = "Kindly provide valid information, contact to application admin"; savedSuccessfully = false; } } catch (Exception ex) { message = ex.Message; savedSuccessfully = false; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(Json(new { SaveMessage = message, IsSuccess = savedSuccessfully })); }
public static void Seed(this ModelBuilder modelBuilder) { var mall1 = new MallDbModel(Guid.NewGuid(), "Ocean Plaza", "10 Pandora Street"); var store1 = new StoreDbModel(Guid.NewGuid(), "Shields and Weapons", "10 Pandora Street", mall1.Id, 0); var category1 = new CategoryDbModel(Guid.NewGuid(), "Laptop"); var category2 = new CategoryDbModel(Guid.NewGuid(), "Mouse"); var category3 = new CategoryDbModel(Guid.NewGuid(), "USB"); var storeCatRel1 = new StoreCategoryDbModel(store1.Id, category1.Id); var storeCatRel2 = new StoreCategoryDbModel(store1.Id, category2.Id); var product1 = new ProductDbModel(Guid.NewGuid(), "HP 450 G1", 20_000, ProductStatus.OnSale, category1.Id); var product11 = new ProductDbModel(Guid.NewGuid(), "HP 450 G1", 20_000, ProductStatus.OnSale, category1.Id); var product111 = new ProductDbModel(Guid.NewGuid(), "HP 450 G1", 20_000, ProductStatus.OnSale, category1.Id); var product1111 = new ProductDbModel(Guid.NewGuid(), "HP 450 G1", 20_000, ProductStatus.OnSale, category1.Id); var product11111 = new ProductDbModel(Guid.NewGuid(), "HP 450 G1", 20_000, ProductStatus.OnSale, category1.Id); var product2 = new ProductDbModel(Guid.NewGuid(), "HP 450 G2", 30_000, ProductStatus.OnSale, category1.Id); var product3 = new ProductDbModel(Guid.NewGuid(), "HP 450 G3", 40_000, ProductStatus.OnSale, category1.Id); var product4 = new ProductDbModel(Guid.NewGuid(), "HP 450 G4", 50_000, ProductStatus.OnSale, category1.Id); var product5 = new ProductDbModel(Guid.NewGuid(), "HP 850 G5", 60_000, ProductStatus.OnSale, category1.Id); var product6 = new ProductDbModel(Guid.NewGuid(), "LogTech G12", 1000, ProductStatus.OnSale, category2.Id); var product7 = new ProductDbModel(Guid.NewGuid(), "X7", 2000, ProductStatus.OnSale, category2.Id); var stPrRel1 = new StoreProductDbModel(store1.Id, product1.Id); var stPrRel11 = new StoreProductDbModel(store1.Id, product11.Id); var stPrRel111 = new StoreProductDbModel(store1.Id, product111.Id); var stPrRel1111 = new StoreProductDbModel(store1.Id, product1111.Id); var stPrRel11111 = new StoreProductDbModel(store1.Id, product11111.Id); var stPrRel2 = new StoreProductDbModel(store1.Id, product2.Id); var stPrRel3 = new StoreProductDbModel(store1.Id, product3.Id); var stPrRel4 = new StoreProductDbModel(store1.Id, product4.Id); var stPrRel5 = new StoreProductDbModel(store1.Id, product5.Id); var stPrRel6 = new StoreProductDbModel(store1.Id, product6.Id); var stPrRel7 = new StoreProductDbModel(store1.Id, product7.Id); modelBuilder.Entity <CategoryDbModel>().HasData( category1, category2, category3 ); modelBuilder.Entity <ProductDbModel>().HasData( product1, product2, product3, product4, product5, product6, product7, product11, product111, product1111, product11111 ); modelBuilder.Entity <MallDbModel>().HasData( mall1 ); modelBuilder.Entity <StoreDbModel>().HasData( store1 ); modelBuilder.Entity <StoreCategoryDbModel>().HasData( storeCatRel1, storeCatRel2 ); modelBuilder.Entity <StoreProductDbModel>().HasData( stPrRel1, stPrRel11, stPrRel111, stPrRel1111, stPrRel11111, stPrRel2, stPrRel3, stPrRel4, stPrRel5, stPrRel6, stPrRel7 ); }
public async Task <CategoryFullResponce> GetCategoryAsync(int id) { CategoryDbModel result = await m_db.Categories.Include(x => (x as CategoryNodeDbModel).ChildCategories).FirstOrDefaultAsync(x => x.Id == id); if (result is null) { throw new NotFoundException(); } return(m_mapper.Map <CategoryFullResponce>(result)); }
public ActionResult CreateNew() { List <Stone> stones = StoneDbModel.GetAllStonesFromDB(); List <Finding> findings = FindingDbModel.GetAllFindingsFromDB(); List <Category> categories = CategoryDbModel.GetAllCategoryFromDB(); ProductItem item = new ProductItem(); item.Stones = stones; item.Findings = findings; item.Categories = categories; return(View(item)); }
public Category DbToDomain(CategoryDbModel item) { CustomValidator.ValidateObject(item); var categoryDbModel = _context.Categories.Where(e => e.Id.Equals(item.Id)) .Include(e => e.ProductDbModels).ThenInclude(e => e.StoreProductRelation) .ThenInclude(e => e.StoreDbModel).FirstOrDefault(); return(new Category( (from productDbModel in categoryDbModel.ProductDbModels select _productMapper.DbToDomain(productDbModel)).ToList(), categoryDbModel.Id, categoryDbModel.Name)); }
public ActionResult Index() { List <Stone> stones = StoneDbModel.GetAllStonesFromDB(); List <Finding> findings = FindingDbModel.GetAllFindingsFromDB(); List <Category> categories = CategoryDbModel.GetAllCategoryFromDB(); ProductItem item = new ProductItem(); var productCollection = ProductDbModel.GetAllProduct(); item.Stones = stones; item.Findings = findings; item.Categories = categories; return(View(productCollection)); }
public JsonResult DeleteCategory(int categoryId) { string message = "Category deleted successfuly"; try { CategoryDbModel.DeleteCategory(categoryId); } catch (Exception ex) { message = ex.Message; Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(Json(new { DeleteMessage = message })); }
public async Task DeletePicAsync(int id) { CategoryDbModel categoryDb = m_db.Categories.FirstOrDefault(x => x.Id == id); if (categoryDb is null) { throw new NotFoundException(); } if (categoryDb.Pic is null) { return; } m_repositoryService.DeleteFileAsync($"{categoryRepoPath}\\{id}\\{categoryDb.Pic.FileName}"); categoryDb.Pic = null; await m_db.SaveChangesAsync(); }
public async Task UploadPicAsync(int id, IFormFile file) { CategoryDbModel categoryDb = m_db.Categories.FirstOrDefault(x => x.Id == id); if (categoryDb is null) { throw new NotFoundException(); } if (categoryDb.Pic is not null) { m_repositoryService.DeleteFileAsync(@$ "{categoryRepoPath}/{id}/{categoryDb.Pic.FileName}"); } SavedFileInfo picInfo = await m_repositoryService.SaveFileAsync(file, @$ "{categoryRepoPath}/{id}", "main", "jpeg"); categoryDb.Pic = m_mapper.Map <PictureInfoDbModel>(picInfo); await m_db.SaveChangesAsync(); }
public ActionResult GetCategoryInformation(int categoryId) { Category category = CategoryDbModel.GetCategoryById(categoryId); return(Json(new { CategoryDetail = category }, JsonRequestBehavior.AllowGet)); }
public ActionResult CreateMainMenu() { List <Category> categoryCollection = CategoryDbModel.GetAllCategoryFromDB(); return(View("Category", categoryCollection)); }