public async Task <IActionResult> Post([FromBody] RolesDTO model) { AddRolesModel role = new DTOMapper <RolesDTO, AddRolesModel>().Serialize(model); var roleid = await _rolesService.AddRoles(role); return(Ok(roleid)); }
public async Task <List <RolesDTO> > GetWorkgroupandDesignations(string Connectionstring) { await Task.Run(() => { _RolesDTOList = new List <RolesDTO>(); try { using (NpgsqlDataReader dataReader = NPGSqlHelper.ExecuteReader(Connectionstring, CommandType.Text, "select recordid,roleid,groupid,groupname,rolename,case when statusid=1 then true else false end as statusid from tblmstgrouproles where statusid=" + Convert.ToInt32(Status.Active) + " order by groupname,rolename desc;")) { while (dataReader.Read()) { RolesDTO _RolemodulesDTO = new RolesDTO { pRoleID = Convert.ToInt64(dataReader["roleid"]), pGroupname = Convert.ToString(dataReader["groupname"]), pGroupid = Convert.ToInt64(dataReader["groupid"]), pRoleactivestatus = Convert.ToBoolean(dataReader["statusid"]), pRoledesignation = Convert.ToString(dataReader["rolename"]), pRecordId = Convert.ToInt64(dataReader["recordid"]) }; _RolesDTOList.Add(_RolemodulesDTO); } } } catch (Exception) { throw; } }); return(_RolesDTOList); }
public RolesDTO Update(RolesDTO caracteristicas) { try { var config = new MapperConfiguration(cfg => { cfg.CreateMap <RolesDTO, Roles>(); }); IMapper mapper = config.CreateMapper(); Roles caracteristicasModel = mapper.Map <RolesDTO, Roles>(caracteristicas); db.Entry(caracteristicasModel).State = EntityState.Modified; db.SaveChanges(); caracteristicas = this.Find(caracteristicas.id); ViewInfoMensaje.setMensaje(controller, MensajeBuilder.EditarMsgSuccess(entidad), Helpers.InfoMensajes.ConstantsLevels.SUCCESS); return(caracteristicas); } catch (Exception) { ViewInfoMensaje.setMensaje(controller, MensajeBuilder.EditarMsgError(entidad), Helpers.InfoMensajes.ConstantsLevels.ERROR); return(caracteristicas); } }
public List <RolesDTO> getList() { try { List <Roles> caracteristicasModel = db.Roles.Where(x => x.estado == true).ToList(); caracteristicasModel = caracteristicasModel.GroupBy(x => x.nombre).Select(x => x.FirstOrDefault()).ToList(); List <RolesDTO> responseList = new List <RolesDTO>();; var config = new MapperConfiguration(cfg => { cfg.CreateMap <Roles, RolesDTO>(); }); IMapper mapper = config.CreateMapper(); //Mapeo de clase caracteristicasModel.ForEach(x => { RolesDTO response = mapper.Map <Roles, RolesDTO>(x); responseList.Add(response); }); return(responseList); } catch (Exception) { throw; } }
public RoleResponse CreateRole(RolesDTO role, ApiContext apiContext) { _context = (MICAUMContext)DbManager.GetContext(apiContext.ProductType, apiContext.ServerType); var _roles = _mapper.Map <AspNetRoles>(role); if (string.IsNullOrEmpty(_roles.Id)) { _roles.Id = Guid.NewGuid().ToString(); DateTime now = DateTime.Now; _roles.ConcurrencyStamp = now.ToString(); _context.AspNetRoles.Add(_roles); _context.SaveChanges(); var _roleDTOs = _mapper.Map <RolesDTO>(_roles); return(new RoleResponse { Status = BusinessStatus.Created, roles = _roleDTOs, Id = _roleDTOs.Id, ResponseMessage = $"Role created successfully! \n Role Name with: {_roleDTOs.Name}" }); //return _roleDTOs; } else { _context.AspNetRoles.Update(_roles); _context.SaveChanges(); var _roleDTOs = _mapper.Map <RolesDTO>(_roles); return(new RoleResponse { Status = BusinessStatus.Created, roles = _roleDTOs, Id = _roleDTOs.Id, ResponseMessage = $"Role modified successfully!" }); //return _roleDTOs; } }
public int UpdateRole(RolesDTO data) { Role dataToUpdate = RolesRequestFormatter.ConvertRespondentInfoFromDTO(data); var response = _unitOfWork.RoleRepository.Update(dataToUpdate); return(response); }
public async Task <IServiceResponse <bool> > Create(RolesDTO role) { return(await HandleApiOperationAsync(async() => { var result = await _roleSvc.CreateAsync(role); return new ServiceResponse <bool>(result); })); }
public IActionResult GetById(string id) { var role = _roleService.GetRoleDetail(id); RolesDTO result = BsonSerializer.Deserialize <RolesDTO>(role.ToJson()); return(Ok(result)); }
public async Task <IServiceResponse <bool> > Update(int id, RolesDTO role) { return(await HandleApiOperationAsync(async() => { await _roleSvc.UpdateRole(id, role); return new ServiceResponse <bool>(true); })); }
public bool SaveRole(RolesDTO _RolesDTO, string Connectionstring) { bool Issaved = false; try { con = new NpgsqlConnection(Connectionstring); if (con.State != ConnectionState.Open) { con.Open(); } trans = con.BeginTransaction(); if (!string.IsNullOrEmpty(_RolesDTO.ptypeofoperation)) { int RoleStatus = 2; if (Convert.ToBoolean(_RolesDTO.pRoleactivestatus) == true) { RoleStatus = 1; } else { RoleStatus = 2; } if (_RolesDTO.ptypeofoperation.Trim().ToUpper() == "CREATE") { NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, "INSERT INTO tblmstgrouproles (roleid,groupid,groupname,rolename,roledescription,issystemrole,statusid,createdby,createddate) VALUES (" + _RolesDTO.pRoleID + "," + _RolesDTO.pGroupid + ", '" + ManageQuote(_RolesDTO.pGroupname) + "','" + ManageQuote(_RolesDTO.pRoledesignation).Trim().ToUpper() + "','', 'N', " + RoleStatus + ", " + _RolesDTO.pCreatedby + ", current_timestamp); "); } else if (_RolesDTO.ptypeofoperation.Trim().ToUpper() == "UPDATE") { NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, "Update tblmstgrouproles set roleid=" + _RolesDTO.pRoleID + ",groupid=" + _RolesDTO.pGroupid + "," + "groupname= '" + ManageQuote(_RolesDTO.pGroupname) + "', rolename= '" + ManageQuote(_RolesDTO.pRoledesignation).Trim().ToUpper() + "',statusid=" + RoleStatus + ",modifiedby=" + _RolesDTO.pCreatedby + ",modifieddate=current_timestamp where recordid=" + _RolesDTO.pRecordId + ";"); } else if (_RolesDTO.ptypeofoperation.Trim().ToUpper() == "DELETE") { NPGSqlHelper.ExecuteNonQuery(trans, CommandType.Text, "Update tblmstgrouproles set statusid=" + Convert.ToInt32(Status.Inactive) + ",modifiedby=" + _RolesDTO.pCreatedby + ",modifieddate=current_timestamp where recordid=" + _RolesDTO.pRecordId + ";"); } trans.Commit(); Issaved = true; } } catch (Exception) { trans.Rollback(); throw; } finally { if (con.State == ConnectionState.Open) { con.Dispose(); con.Close(); con.ClearPool(); trans.Dispose(); } } return(Issaved); }
public ActionResult EditItem([Bind(Include = "id,nombre")] RolesDTO caracteristicass) { if (ModelState.IsValid) { caracteristicass = caracteristicasDAO.Update(caracteristicass); return(PartialView("Confirm", caracteristicass)); } return(PartialView("Edit", caracteristicass)); }
public RolesDTO GetAllRoles() { var roles = new RolesDTO() { Roles = new List <Role>() }; roles.Roles = context.Roles.ToList(); return(roles); }
public Roles ConvertTOModel(RolesDTO obj) { var roles = new Roles() { RoleID = obj.RoleID, Name = obj.Name }; return(roles); }
public RolesDTO ConvertTODTO(Roles obj) { var rolesDTO = new RolesDTO() { RoleID = obj.RoleID, Name = obj.Name }; return(rolesDTO); }
public ActionResult CreateNew([Bind(Include = "id,nombre")] RolesDTO caracteristicas) { if (ModelState.IsValid) { caracteristicasDAO.Add(caracteristicas); return(PartialView("Confirm", caracteristicas)); } return(PartialView("Create", caracteristicas)); }
public async Task <IActionResult> GetRole([FromBody] RolesDTO rolesDTO) { var role = await _roleManager.FindByIdAsync(rolesDTO.Id); if (role != null) { return(Ok(role)); } return(NotFound()); }
public async Task <ActionResult> Post([FromBody] RolesDTO entity) { try { return(Ok(await _rolesService.Add(entity))); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public IHttpActionResult AddRoles([FromBody] RolesDTO roleDTO) { if (roleDTO == null) { return(BadRequest()); } var results = _roleService.AddRoles(roleDTO); return(Ok(results)); }
public async Task <IActionResult> Post([FromBody] RolesDTO rolesDto) { var role = _mapper.Map <Roles>(rolesDto); await _rolesServices.Add(role); rolesDto = _mapper.Map <RolesDTO>(role); var response = new GenericResponse <RolesDTO>(rolesDto); return(Ok(response)); }
private void CheckForRightToCreateSuperuser(RolesDTO newUserRole) { string currentUserRole = GetCurrentUserRole(); if (newUserRole != null && (newUserRole.Name == Role.Superuser) && (currentUserRole != Role.Superuser)) { throw new Exception("Only superuser can create superuser"); } }
// GET: ConfiguracionEmpresa/RazonesSociales/Delete/5 public ActionResult DeleteItem(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RolesDTO caracteristica = caracteristicasDAO.Find(id); if (caracteristica == null) { return(HttpNotFound()); } return(PartialView("Delete", caracteristica)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RolesDTO peridos = caracteristicasDAO.Find(id); if (peridos == null) { return(HttpNotFound()); } return(PartialView(peridos)); }
public RolesDTO GetRoles() { RolesDTO rolesList = UserDBContext.GetRoles(); if (rolesList.Roles.Count() <= 0) { throw new NoRolesFoundException(); } else { return(rolesList); } }
public ActionResult RolesCreate(RolesDTO data) { List <SelectListItem> businessGroupList = new List <SelectListItem>(); foreach (var row in _bgService.GetBusinessGroupList()) { businessGroupList.Add(new SelectListItem { Text = row.BgName, Value = row.BgId.ToString() }); } ViewBag.BusinessGroupList = businessGroupList; try { if (data.RoleDataAccessAll == false) { if (data.BusinessGroup == null) { ViewBag.Error = "You must choose at least one Business Group and/or Offices"; return(View(data)); } } RolesDTO resRoles = new RolesDTO(); RolesBusinessGroupAccessDTO dataForBg = new RolesBusinessGroupAccessDTO(); RolesBusinessGroupAccessDTO resForBg = new RolesBusinessGroupAccessDTO(); resRoles = _rolesService.InsertRoles(data); if (data.BusinessGroup != null) { foreach (int item in data.BusinessGroup) { dataForBg.BusinssGroupId = item; dataForBg.RoleId = resRoles.RoleId; resForBg = _rolesBusinessGroupAccessService.Insert(dataForBg); } } ViewBag.success = "New role added as " + data.RoleName; return(RedirectToAction("Roles")); } catch (Exception Ex) { ViewBag.error = Ex.Message; return(View()); } }
public RegistrationController() { userBusinessContext = new UserBusinessContext(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <RegistrationViewModel, UserRegisterDTO>(); }); var configRoles = new MapperConfiguration(cfg => { cfg.CreateMap <RolesDTO, RegistrationViewModel>(); }); RegistrationViewModelMapper = new Mapper(config); RegisterationRoleMapper = new Mapper(configRoles); roleList = userBusinessContext.GetRoles(); }
public RolesDTO AddRoles(RolesDTO obj) { try { var objRole = ConvertTOModel(obj); var role = _roleRepository.SaveorUpdate(objRole); log.Info("Role Added Successfully"); return(ConvertTODTO(role)); } catch (Exception ex) { log.ErrorFormat("Exception occured while Adding new Role Ex:{0}", ex.Message); return(null); } }
public RolesDTO GetRoles() { List <Role> roleList = FutureKartContext.Roles.Where(r => r.Name != "ADMIN").ToList(); Debug.WriteLine(FutureKartContext.Roles.Where(r => r.Name != "ADMIN").ToList()); if (roleList.Count() <= 0) { throw new NoRolesFoundException("No roles found exception"); } IEnumerable <Role> rolesListIEnumerable = roleList.AsEnumerable(); RolesDTO rolesDTO = new RolesDTO(); rolesDTO.Roles = RoleMapper.Map <IEnumerable <Role>, IEnumerable <RoleDTO> >(rolesListIEnumerable); return(rolesDTO); }
public static Role ConvertRespondentInfoFromDTO(RolesDTO rolesDTO) { Mapper.CreateMap <RolesDTO, Role>().ConvertUsing( m => { return(new Role { RoleId = m.RoleId, RoleName = m.RoleName, RoleDetails = m.RoleDetails, RoleDataAccessAll = m.RoleDataAccessAll }); }); return(Mapper.Map <RolesDTO, Role>(rolesDTO)); }
public async Task <Users> Add(Users entity) { try { RolesDTO newUserRole = await _unitOfWork.RolesRepo.GetByIdDTO(entity.RolesId); CheckForRightToCreateSuperuser(newUserRole); var res = await Task.FromResult <Users>(_unitOfWork.UsersRepo.Add(entity)); return(res); } catch (Exception ex) { throw base._errorService.CreateException(ex, this._moduleCode, MethodsIndex.ADD_ENTITY); } }
public async Task <IActionResult> Put(int id, RolesDTO rolesDto) { try { var roles = _mapper.Map <Roles>(rolesDto); roles.Rol_Id = id; await _rolesServices.Update(roles); var response = new GenericResponse <bool>(true); return(Ok(response)); } catch (Exception ex) { throw new BusinessException(MessageCodes.PROPERTY_NO_VALID, GetErrorDescription(MessageCodes.PROPERTY_NO_VALID), ex.Message); } }