public bool deleteCategory(string id) { try { Models.tblCategory tblCategory = _dbContext.tblCategories.Find(id); if (tblCategory == null) { return(false); } else { _dbContext.tblCategories.Remove(tblCategory); _dbContext.SaveChanges(); return(true); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(false); }
public bool updateCategory(Category model) { try { Models.tblCategory category = _dbContext.tblCategories.Where(s => model.CategoryID.Equals(s.CategoryID)).FirstOrDefault(); if (category.CategoryName != null) { var config = new MapperConfiguration(cfg => cfg.CreateMap <Category, Models.tblCategory>()); var mapper = new Mapper(config); mapper.Map <Category, Models.tblCategory>(model, category); _dbContext.SaveChanges(); return(true); } } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.UpdateException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { Console.WriteLine(ex.InnerException); } catch (Exception ex) { return(false); } return(false); }
public bool createCategory(Category model) { try { var config = new MapperConfiguration(cfg => cfg.CreateMap <Category, Models.tblCategory>()); var mapper = new Mapper(config); Models.tblCategory category = mapper.Map <Models.tblCategory>(model); int count = _dbContext.tblCategories.Count(); category.CategoryID = "CA00" + (count + 1); _dbContext.tblCategories.Add(category); _dbContext.SaveChanges(); return(true); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.UpdateException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { Console.WriteLine(ex.InnerException); } catch (Exception ex) { return(false); } return(false); }