public bool EditCatalog(int id, string name, int?parentId) { try { using (var model = new LCDBEntities()) { var catalog = model.Catalogs.FirstOrDefault(c => c.ID == id); if (catalog == null) { throw new CatalogNotFoundException("Catalog with this id not found in database"); } catalog.Name = name; catalog.ParentID = parentId; model.SaveChanges(); return(true); } } catch (Exception ex) { if (ex is CatalogNotFoundException) { throw ex; } return(false); } }
public bool SetStatusAsActive(int id, bool isActive) { try { using (var model = new LCDBEntities()) { var catalog = model.Catalogs.FirstOrDefault(c => c.ID == id); if (catalog == null) { throw new CatalogNotFoundException("Catalog with this id not found in database"); } catalog.IsActive = isActive; model.SaveChanges(); return(true); } } catch (Exception ex) { if (ex is CatalogNotFoundException) { throw ex; } return(false); } }
public bool ChangeStatus(Menu menu, bool status) { try { using (LCDBEntities model = new LCDBEntities()) { var _menu = model.Menus.FirstOrDefault(o => o.ID == menu.ID); if (_menu == null) { throw new MenuNotFoundException("Menu not found with this id"); } _menu.IsActive = status; model.SaveChanges(); } return(true); } catch (Exception ex) { if (ex is MenuNotFoundException) { throw ex; } return(false); } }
public bool EditMenu(Menu menu) { try { using (LCDBEntities model = new LCDBEntities()) { var _menu = model.Menus.FirstOrDefault(m => m.ID == menu.ID); if (_menu == null) { throw new MenuNotFoundException("Menu not found with this id"); } _menu.IsActive = menu.IsActive; _menu.Name = menu.Name; _menu.Description = menu.Description; _menu.ParentID = menu.ParentID; _menu.EventName = menu.EventName; _menu.OrderNumber = menu.OrderNumber; model.SaveChanges(); } return(true); } catch (Exception ex) { if (ex is MenuNotFoundException) { throw ex; } return(false); } }
public bool AddMenu(Menu menu) { try { using (LCDBEntities model = new LCDBEntities()) { Menu _menu = new Menu(); _menu.ID = menu.ID; _menu.Name = menu.Name; _menu.Description = menu.Description; _menu.ParentID = menu.ParentID; _menu.EventName = menu.EventName; _menu.OrderNumber = menu.OrderNumber; _menu.IsActive = menu.IsActive; model.Menus.Add(_menu); model.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool AddUser(UserClass user) { try { using (LCDBEntities model = new LCDBEntities()) { using (TransactionScope t = new TransactionScope()) { try { if (model.Users.Any(i => i.PersonalNumber.Equals(user.PersonalNumber))) { throw new Exception("This user already exists..."); } User u = new User(); u.PersonalNumber = user.PersonalNumber; u.FirstName = user.FirstName; u.LastName = user.LastName; u.EMail = user.EMail; u.Password = user.Password; u.BirthDate = user.BirthDate; u.NationalityID = user.NationalityID; u.Avatar = user.Avatar; u.Address1 = user.Address1; u.Address2 = user.Address2; u.PhoneNumber = user.PhoneNumber; u.GenderId = user.GenderId; model.Users.Add(u); UserRole ur = new UserRole(); ur.RoleID = user.RoleId; ur.UserID = u.ID; ur.IsActive = true; model.UserRoles.Add(ur); model.SaveChanges(); t.Complete(); return(true); } catch (Exception ex) { t.Dispose(); throw new Exception(ex.Message); } } } } catch (Exception ex) { return(false); } }
public bool BlockUnblock(int userId, int roleId) { try { LCDBEntities model = new LCDBEntities(); if (!model.UserRoles.Any(i => i.UserID == userId && i.RoleID == roleId)) { throw new Exception("role not found..."); } UserRole u = model.UserRoles.Where(i => i.UserID == userId && i.RoleID == roleId).First(); u.IsActive = !u.IsActive; model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool UpdateRole(RoleClass role) { try { LCDBEntities model = new LCDBEntities(); if (!model.Roles.Any(i => i.Name.Equals(role.Name))) { throw new Exception("This role not found..."); } Role r = model.Roles.Where(i => i.Name.Equals(role.Name)).First(); r.Name = role.Name; r.Description = role.Description; model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool AddNewCatalog(ICatalog catalog) { try { using (var model = new LCDBEntities()) { var newCatalog = new Catalog() { Name = catalog.Name, ParentID = catalog.ParentId, IsActive = catalog.IsActive }; model.Catalogs.Add(newCatalog); model.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public bool AddRole(RoleClass role) { try { LCDBEntities model = new LCDBEntities(); if (model.Roles.Any(i => i.Name.Equals(role.Name))) { throw new Exception("This Role already exists..."); } Role r = new Role(); r.Name = role.Name; r.Description = role.Description; model.Roles.Add(r); model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool AssignNewRole(int userId, int roleId) { try { LCDBEntities model = new LCDBEntities(); if (model.UserRoles.Any(i => i.UserID == userId && i.RoleID == roleId)) { throw new Exception("The Role is already assigned for this User..."); } UserRole ur = new UserRole(); ur.UserID = userId; ur.RoleID = roleId; ur.IsActive = true; model.UserRoles.Add(ur); model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool UpdateUser(UserClass user) { try { using (LCDBEntities model = new LCDBEntities()) { using (TransactionScope t = new TransactionScope()) { try { if (!model.Users.Any(i => i.PersonalNumber.Equals(user.PersonalNumber))) { throw new Exception("This user not found..."); } User u = model.Users.Where(i => i.PersonalNumber.Equals(user.PersonalNumber)).First(); u.FirstName = user.FirstName; u.LastName = user.LastName; u.BirthDate = user.BirthDate; u.NationalityID = user.NationalityID; u.Avatar = user.Avatar; u.Address1 = user.Address1; u.Address2 = user.Address2; u.PhoneNumber = user.PhoneNumber; u.GenderId = user.GenderId; if (!model.UserRoles.Any(i => i.UserID == u.ID)) { throw new Exception("role not found..."); } UserRole ur = model.UserRoles.Where(i => i.UserID == u.ID).First(); ur.RoleID = user.RoleId; model.SaveChanges(); t.Complete(); return(true); } catch (Exception ex) { t.Dispose(); throw new Exception(ex.Message); } } } } catch (Exception ex) { return(false); } try { LCDBEntities model = new LCDBEntities(); model.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }