Example #1
0
        public async Task <UserChefResponse> UpdateAsync(int id, UserChef userChef)
        {
            var existingUserChef = await _userChefRepository.FindById(id);

            if (existingUserChef == null)
            {
                return(new UserChefResponse("UserChef not found"));
            }
            existingUserChef.Name        = userChef.Name;
            existingUserChef.Lastname    = userChef.Lastname;
            existingUserChef.Certificate = userChef.Certificate;
            existingUserChef.Email       = userChef.Email;
            existingUserChef.Password    = userChef.Password;
            existingUserChef.Picture     = userChef.Picture;
            existingUserChef.Date        = userChef.Date;
            try
            {
                _userChefRepository.Update(existingUserChef);
                await _unitOfWork.CompleteAsync();

                return(new UserChefResponse(existingUserChef));
            }
            catch (Exception ex)
            {
                return(new UserChefResponse($"An error ocurred while updating the UserChef: {ex.Message}"));
            }
        }
Example #2
0
        public async Task <IActionResult> AssignUserChef(int userCommonId, int userChefId)
        {
            var result = await _commonChefService.AssingCommonChefAsync(userCommonId, userChefId);

            if (!result.Succes)
            {
                return(BadRequest(result.Message));
            }
            UserChef userChef = _userChefService.GetByIdAsync(userChefId).Result.Resource;
            var      resource = _mapper.Map <UserChef, UserChefResource>(userChef);

            return(Ok(resource));
        }
Example #3
0
        public async Task <UserChefResponse> SaveAsync(UserChef userChef)
        {
            try
            {
                await _userChefRepository.AddAsync(userChef);

                await _unitOfWork.CompleteAsync();

                return(new UserChefResponse(userChef));
            }
            catch (Exception ex)
            {
                return(new UserChefResponse($"An error ocurred while saving the UserChef: {ex.Message}"));
            }
        }
Example #4
0
 public void Update(UserChef userChef)
 {
     _context.UserChefs.Update(userChef);
 }
Example #5
0
 public void Remove(UserChef userChef)
 {
     _context.UserChefs.Remove(userChef);
 }
Example #6
0
 public async Task AddAsync(UserChef userChef)
 {
     await _context.UserChefs.AddAsync(userChef);
 }