Esempio n. 1
0
        public async Task <IActionResult> Update(int id, [FromBody] SaveUserModuleRightsResource userModuleRightsResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var usermoduleright = await userModuleRightRepository.GetOne(id);

            if (usermoduleright == null)
            {
                return(NotFound());
            }

            usermoduleright = mapper.Map(userModuleRightsResource, usermoduleright);

            if (await unitOfWork.CompleteAsync() == false)
            {
                throw new Exception(message: $"Updating user module right with id: {id} failed on save");
            }

            usermoduleright = await userModuleRightRepository.GetOne(usermoduleright.Id);

            var result = mapper.Map <UserModuleRight, ViewUserModuleRightsResource>(usermoduleright);

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([FromBody] SaveUserModuleRightsResource userModuleRightsResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var usermoduleright = mapper.Map <SaveUserModuleRightsResource, UserModuleRight>(userModuleRightsResource);

            userModuleRightRepository.Add(usermoduleright);

            if (await unitOfWork.CompleteAsync() == false)
            {
                throw new Exception(message: "Create new user module right failed on save");
            }

            usermoduleright = await userModuleRightRepository.GetOne(usermoduleright.Id);

            var result = mapper.Map <UserModuleRight, ViewUserModuleRightsResource>(usermoduleright);

            return(Ok(result));
        }