Ejemplo n.º 1
0
 internal ResponseModel Update(NewsCategory newsCategory)
 {
     return(_newsCategoryRepository.Update(newsCategory));
 }
Ejemplo n.º 2
0
        public ActionResult <ApiResponse <UserDto> > Update(int id, UserDto item)
        {
            var                response           = new ApiResponse <UserDto>();
            UserUpdateDto      userDto            = _mapper.Map <UserUpdateDto>(item);
            HierarchyUpdateDto hierarchyUpdateDto = _mapper.Map <HierarchyUpdateDto>(item.Hierarchies[0]);
            var                permissions        = _mapper.Map <List <PermissionUpdateDto> >(item.Hierarchies[0].Permissions);

            try
            {
                var user = _userRepository.Find(c => c.Id == id);

                //TODO Pending validate District Id

                if (user == null)
                {
                    response.Message = $"User id { id } Not Found";
                    return(NotFound(response));
                }
                var hie = _hierarchyRepository.Find(h => h.Id == item.Hierarchies[0].Id);
                if (hie == null)
                {
                    response.Message = $"User id { id } Not Found";
                    return(NotFound(response));
                }
                //var per = _permissionRepository.FindBy(p => p.HierarchyId == item.Hierarchies[0].Id);
                //if (hie == null)
                //{
                //    response.Message = $"User id { id } Not Found";
                //    return NotFound(response);
                //}
                int i = 0;
                foreach (PermissionUpdateDto permission in permissions)
                {
                    var per = _permissionRepository.Find(p => p.Id == item.Hierarchies[0].Permissions[i].Id);
                    if (per == null)
                    {
                        //insert
                        Permission permissioncreate = _permissionRepository.Add(_mapper.Map <Permission>(permission));
                        //response.Result = _mapper.Map<UserDto>(user);
                    }
                    else
                    {
                        //update
                        _mapper.Map(permission, per);
                        _permissionRepository.Update(per, item.Hierarchies[0].Permissions[i].Id);
                    }
                    i += 1;
                }

                _mapper.Map(hierarchyUpdateDto, hie);
                _hierarchyRepository.Update(hie, item.Hierarchies[0].Id);

                _mapper.Map(userDto, user);
                _userRepository.Update(user, id);
                response.Result = _mapper.Map <UserDto>(_userRepository.Find(u => u.Id == id));
                //Hierarchy hierarchy = _mapper.Map<Hierarchy>(item.Hierarchies[0]);
                //_hierarchyRepository.Update(hierarchy, hierarchy.Id);
            }
            catch (Exception ex)
            {
                response.Result  = null;
                response.Success = false;
                response.Message = "Internal server error";
                _logger.LogError($"Something went wrong: { ex.ToString() }");
                return(StatusCode(500, response));
            }

            return(Ok(response));
        }
Ejemplo n.º 3
0
 internal ResponseModel Update(PageTemplate pageTemplate)
 {
     return(_pageTemplateRepository.Update(pageTemplate));
 }