public IHttpActionResult PutRols(int id, Rols rols) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != rols.Id) { return(BadRequest()); } db.Entry(rols).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException e) { if (!RolsExists(id)) { return(NotFound()); } else { HttpResponseMessage errorResponse = new HttpResponseMessage(HttpStatusCode.NotImplemented); errorResponse.ReasonPhrase = e.Message; throw new HttpResponseException(errorResponse); } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { Rols rols = db.Rols.Find(id); db.Rols.Remove(rols); db.SaveChanges(); return(RedirectToAction("RolList")); }
public IHttpActionResult GetRols(int id) { Rols rols = db.Rols.Find(id); if (rols == null) { return(NotFound()); } return(Ok(rols)); }
public IHttpActionResult PostRols(Rols rols) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Rols.Add(rols); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = rols.Id }, rols)); }
public IActionResult GetRolByName([FromBody] Rols statusParam) { try { var _getRolByName = _loginService.getRolByName(statusParam); return(Ok(_getRolByName)); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
// GET: Rols/Edit/5 public ActionResult RolEdit(int?id) { Rols rols = db.Rols.Where(x => x.ID == id).SingleOrDefault(); RolVM model = new RolVM() { ID = rols.ID, RolName = rols.Name, Seviye = rols.Seviye.Value }; return(View(model)); }
// GET: Rols/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Rols rols = db.Rols.Find(id); if (rols == null) { return(HttpNotFound()); } return(View(rols)); }
public IHttpActionResult DeleteRols(int id) { Rols rols = db.Rols.Find(id); if (rols == null) { return(NotFound()); } db.Rols.Remove(rols); db.SaveChanges(); return(Ok(rols)); }
public ActionResult RolCreate(/*[Bind(Include = "ID,Seviye,Name")]*/ RolVM model) { if (ModelState.IsValid) { Rols rols = new Rols(); rols.Name = model.RolName; rols.Seviye = model.Seviye; db.Rols.Add(rols); db.SaveChanges(); return(RedirectToAction("RolList")); } return(View(model)); }
public void CreateUser(UserRequest statusParam) { bool userUnique = isUserUnique(statusParam.Username, statusParam.Email); if (string.IsNullOrWhiteSpace(statusParam.Password)) { throw new AppExceptions("Password is required"); } Rols groupValue = new Rols(); groupValue.RolName = statusParam.Group; var groupExist = getRolByName(groupValue); if (userUnique) { if (groupExist != null) { User user = new User(); Utils.Map(user, statusParam, "Create"); byte[] passwordHashed, passwordKey; CreateUserPassword_Hash(statusParam.Password, out passwordHashed, out passwordKey); user.Password = BitConverter.ToString(passwordHashed); user.Key = BitConverter.ToString(passwordKey); var code = GenerateNewRandomCode(); bool value = CodeExist(int.Parse(code)); if (!value) { throw new AppExceptions("Code already exist"); } user.accessCode = int.Parse(code); InsertSQl(user, groupExist.Id); } else { throw new AppExceptions("Group does not exist"); } } else { throw new AppExceptions("User Already exist"); } }
public List <Rols> Roles() { var _roles = ListRoles(); List <Rols> __rols = new List <Rols>(); if (_roles != null) { foreach (Rols rol in _roles) { Rols rols = new Rols(); rols.Id = rol.Id; rols.RolName = rol.RolName; __rols.Add(rols); } } return(__rols); }
protected void Button1_Click(object sender, EventArgs e) { try { string _indice_usuario = this.cboUsuario.SelectedItem.Value.ToString(); string rol = this.cboRol.SelectedItem.Value.ToString(); AcesoDatos a = new AcesoDatos(); a.Ejecutar("update vendedores set rol = '" + rol + "' where indice = '" + _indice_usuario + "' "); Rols.Text = "Rol agregado con exito"; Rols.DataBind(); } catch (Exception es) { Helper.RegistrarEvento("Asignando Roles. " + es.Message); } }
public Rols getRolById(Rols statusParam) { if (statusParam == null) { throw new AppExceptions("Rol Id is required"); } var _rol = GetRolById(statusParam.Id); Rols _getRolReturn = new Rols(); if (_rol != null) { _getRolReturn.Id = _rol.Id; _getRolReturn.RolName = _rol.RolName; } else { throw new AppExceptions("Rol not found"); } return(_getRolReturn); }
public Rols getRolByName(Rols statusParam) { if (string.IsNullOrEmpty(statusParam.RolName)) { throw new AppExceptions("Rol name is required"); } var _rol = GetRolByName(statusParam.RolName); Rols _getRolReturn = new Rols(); if (_rol != null) { _getRolReturn.Id = _rol.Id; _getRolReturn.RolName = _rol.RolName; } else { throw new AppExceptions("Rol not found"); } return(_getRolReturn); }
private Rols GetRolByName(string name) { Rols rol = null; using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM tittan.Group where Name='" + name + "'", conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { rol = new Rols(); rol.Id = int.Parse(reader["GroupId"].ToString()); rol.RolName = reader["Name"].ToString(); } } } return(rol); }
private List <Rols> ListRoles() { List <Rols> _roles = new List <Rols>(); using (MySqlConnection conn = GetConnection()) { conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM tittan.Group", conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Rols _rols = new Rols(); _rols.Id = int.Parse(reader["GroupId"].ToString()); _rols.RolName = reader["Name"].ToString(); _roles.Add(_rols); } } } return(_roles); }
public void UpdateUser(UserRequest statusParam) { if (statusParam == null) { throw new AppExceptions("User Id is required"); } else { var user = GetUserByIdIncludePassword(statusParam.Id); var _updateUser = statusParam; if (user == null) { throw new AppExceptions("User not found"); } Unique userUnique = isUserExist(statusParam.Username, statusParam.Email); Rols groupValue = new Rols(); groupValue.RolName = statusParam.Group; var groupExist = getRolByName(groupValue); if (_updateUser.Username != user.Username || _updateUser.Email != user.Email) { if (!userUnique.usernameUnique || !userUnique.emailUnique) { throw new AppExceptions("Username or email already exist"); } else { if (groupExist == null) { throw new AppExceptions("Group does not exist"); } } } Utils.Map(user, statusParam, "Update"); string requestCode = _updateUser.accessCode.ToString(); if (user.accessCode != _updateUser.accessCode) { if (requestCode.Distinct().Count() == 1) { throw new AppExceptions("Code can to have same digits"); } bool value = CodeExist(int.Parse(requestCode)); if (!value) { throw new AppExceptions("Code already exist"); } user.accessCode = int.Parse(requestCode); } user.GroupId = groupExist.Id; if (!string.IsNullOrWhiteSpace(statusParam.Password)) { byte[] passwordHashed, passwordKey; CreateUserPassword_Hash(statusParam.Password, out passwordHashed, out passwordKey); user.Password = BitConverter.ToString(passwordHashed); user.Key = BitConverter.ToString(passwordKey); } UpdateUserSQL(user); } }