Пример #1
0
        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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        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;
            }
        }
Пример #6
0
        public int UpdateRole(RolesDTO data)
        {
            Role dataToUpdate = RolesRequestFormatter.ConvertRespondentInfoFromDTO(data);
            var  response     = _unitOfWork.RoleRepository.Update(dataToUpdate);

            return(response);
        }
Пример #7
0
        public async Task <IServiceResponse <bool> > Create(RolesDTO role)
        {
            return(await HandleApiOperationAsync(async() => {
                var result = await _roleSvc.CreateAsync(role);

                return new ServiceResponse <bool>(result);
            }));
        }
Пример #8
0
        public IActionResult GetById(string id)
        {
            var role = _roleService.GetRoleDetail(id);

            RolesDTO result = BsonSerializer.Deserialize <RolesDTO>(role.ToJson());

            return(Ok(result));
        }
Пример #9
0
        public async Task <IServiceResponse <bool> > Update(int id, RolesDTO role)
        {
            return(await HandleApiOperationAsync(async() => {
                await _roleSvc.UpdateRole(id, role);

                return new ServiceResponse <bool>(true);
            }));
        }
Пример #10
0
        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);
        }
Пример #11
0
 public ActionResult EditItem([Bind(Include = "id,nombre")] RolesDTO caracteristicass)
 {
     if (ModelState.IsValid)
     {
         caracteristicass = caracteristicasDAO.Update(caracteristicass);
         return(PartialView("Confirm", caracteristicass));
     }
     return(PartialView("Edit", caracteristicass));
 }
Пример #12
0
        public RolesDTO GetAllRoles()
        {
            var roles = new RolesDTO()
            {
                Roles = new List <Role>()
            };

            roles.Roles = context.Roles.ToList();
            return(roles);
        }
Пример #13
0
        public Roles ConvertTOModel(RolesDTO obj)
        {
            var roles = new Roles()
            {
                RoleID = obj.RoleID,
                Name   = obj.Name
            };

            return(roles);
        }
Пример #14
0
        public RolesDTO ConvertTODTO(Roles obj)
        {
            var rolesDTO = new RolesDTO()
            {
                RoleID = obj.RoleID,
                Name   = obj.Name
            };

            return(rolesDTO);
        }
Пример #15
0
        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());
        }
Пример #17
0
 public async Task <ActionResult> Post([FromBody] RolesDTO entity)
 {
     try
     {
         return(Ok(await _rolesService.Add(entity)));
     }
     catch (Exception ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
Пример #18
0
        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));
        }
Пример #20
0
        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");
            }
        }
Пример #21
0
        // 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));
        }
Пример #22
0
        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));
        }
Пример #23
0
        public RolesDTO GetRoles()
        {
            RolesDTO rolesList = UserDBContext.GetRoles();


            if (rolesList.Roles.Count() <= 0)
            {
                throw new NoRolesFoundException();
            }
            else
            {
                return(rolesList);
            }
        }
Пример #24
0
        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());
            }
        }
Пример #25
0
        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();
        }
Пример #26
0
 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);
     }
 }
Пример #27
0
        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);
        }
Пример #28
0
 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));
 }
Пример #29
0
        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);
            }
        }