Exemplo n.º 1
0
        //To save role and access rights
        public IHttpActionResult SaveRoleAndRights(RolesModel rolesModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    RolesData roleRightsData = new RolesData();

                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <RolesModel, RolesDTO>();
                        cfg.CreateMap <RoleRightsMappingModel, RoleRightsMappingDTO>();
                    });
                    IMapper mapper = config.CreateMapper();

                    var roleRights = mapper.Map <RolesModel, RolesDTO>(rolesModel);

                    roleRightsData.SaveRoleAndRights(roleRights);

                    return(Created("api/SaveRoleAndRights", true));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Could not save roles and rights"));
            }
        }