public int Insert(RolesModel entity) { TblRoles obj = _mapper.Map <RolesModel, TblRoles>(entity); _repository.Insert(obj); return(obj.RoleId); }
public int Update(RolesModel entity) { TblRoles obj = _mapper.Map <RolesModel, TblRoles>(entity); _repository.Update(obj); return(obj.RoleId); }
public async Task <IActionResult> PutTblRoles(int id, TblRoles tblRoles) { if (id != tblRoles.Id) { return(BadRequest()); } _context.Entry(tblRoles).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblRolesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool ChangeStatus(int id) { TblRoles obj = _repository.GetById(id); obj.IsActive = !obj.IsActive; _repository.Update(obj); return(true); }
public ActionResult DeleteConfirmed(int id) { TblRoles tblRoles = db.Roles.Find(id); db.Roles.Remove(tblRoles); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "IdRol,Rol,Descripcion")] TblRoles tblRoles) { if (ModelState.IsValid) { db.Entry(tblRoles).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblRoles)); }
public ActionResult Create([Bind(Include = "IdRol,Rol,Descripcion")] TblRoles tblRoles) { if (ModelState.IsValid) { db.Roles.Add(tblRoles); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblRoles)); }
// GET: Roles/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TblRoles tblRoles = db.Roles.Find(id); if (tblRoles == null) { return(HttpNotFound()); } return(View(tblRoles)); }
public static async Task <bool> AddUserToRoleAsync(TblUsers user, int roleType, string description = null) { using (ComputerAccessoriesContext _db = new ComputerAccessoriesContext()) { try { var role = _db.TblRoles.Where(x => x.Id == roleType).FirstOrDefault(); if (role == null) { TblRoles newRole = new TblRoles { Name = description, NormalizedName = "Default", }; _db.TblRoles.Add(newRole); await _db.SaveChangesAsync(); TblUserRole userRole = new TblUserRole() { RoleId = newRole.Id, UserId = user.Id }; _db.TblUserRole.Add(userRole); await _db.SaveChangesAsync(); return(true); } else { TblUserRole userRole = new TblUserRole() { RoleId = roleType, UserId = user.Id }; _db.TblUserRole.Add(userRole); await _db.SaveChangesAsync(); return(true); } } catch (Exception e) { return(false); throw; } } }
public static RolesObj MagicMapper(this TblRoles item) { if (item == null) { return(null); } RolesObj obj = new RolesObj { RolesId = item.RolesId, SiteId = item.SiteId, RoleDesc = item.Role.LabelE, SiteDesc = item.Site.TitleShortE }; return(obj); }
public async Task <ActionResult <TblRoles> > PostTblRoles(TblRoles tblRoles) { _context.TblRoles.Add(tblRoles); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TblRolesExists(tblRoles.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetTblRoles", new { id = tblRoles.Id }, tblRoles)); }
public void Configuration(IAppBuilder app) { Database.SetInitializer(new CreateDatabaseIfNotExists <DBContextModel>()); DBContextModel context = new DBContextModel(); TblUsers admin = new TblUsers { Email = "[email protected]", IsActive = true, Password = "******", RegisterDate = DateTime.Now }; if (!context.TblUsers.Any(x => x.Email == admin.Email)) { context.TblUsers.Add(admin); context.SaveChanges(); } String[] roles = { "student", "teacher", "secretary", "assistant", "guardian", "admin" }; Array.ForEach(roles, role => { if (!context.TblRoles.Any(x => x.Name == role)) { var newRole = new TblRoles { Name = role }; context.TblRoles.Add(newRole); context.SaveChanges(); if (role == "admin") { context.TblUserRoles.Add(new TblUserRoles { RoleFK = newRole.ID, UserFK = admin.ID }); context.SaveChanges(); } } }); }
public RolesModel GetById(int id) { TblRoles obj = _repository.GetById(id); return(obj == null ? new RolesModel() : Map(obj)); }
private RolesModel Map(TblRoles unit) { return(_mapper.Map <RolesModel>(unit)); }