Пример #1
0
        public async Task <Pet> UpdatePetAsync(PetUpdateRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            PetTableModel table = null;

            if (request.Id.HasValue)
            {
                table = await _petDataAccess.GetPetByIdAsync(request.Id.Value)
                        .ConfigureAwait(false);
            }
            else if (request.Code.HasValue)
            {
                table = await _petDataAccess.GetPetByCodeAsync(request.Code.Value)
                        .ConfigureAwait(false);
            }

            table = _petMapper.MapUpdateRequestToTable(request, table);
            await _petDataAccess.UpdatePetAsync(table);

            var updatedTable = await _petDataAccess.GetPetByIdAsync(table.Id)
                               .ConfigureAwait(false);

            return(_petMapper.MapPetTableToPet(updatedTable, false));
        }
Пример #2
0
        public async Task <Pet> Put(PetUpdateRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(await _petProvider.UpdatePetAsync(request)
                   .ConfigureAwait(false));
        }
Пример #3
0
        internal void UpdatePet(PetUpdateRequest PetUpdateRequest)
        {
            logger.Trace("Recived pet update request");
            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                if (PetUpdateRequest == null || PetUpdateRequest.id <= 0 ||
                    String.IsNullOrEmpty(PetUpdateRequest.petName))
                {
                    logger.Error("Pet update Request body is empty or required fields not found");
                    throw new CustomException("Pet update request invalid", (int)ErrorCode.VALIDATIONFAILED);
                }
                using (var ctx = new PetWhizzEntities())
                {
                    pet Pet = ctx.pets.Where(a => a.id == PetUpdateRequest.id).FirstOrDefault();
                    if (Pet == null)
                    {
                        logger.Error("Pet record is not fount for petId - " + PetUpdateRequest.id.ToString());
                        throw new CustomException("Pet object not found", (int)ErrorCode.NORECORDFOUND);
                    }
                    //looking for authorization
                    if (Pet.petOwners.Where(a => a.userId == currentUser.userId).FirstOrDefault() == null)
                    {
                        logger.Error("Pet record is not fount for petId - " + PetUpdateRequest.id.ToString() + " and userId - " + currentUser.userId);
                        throw new CustomException("Pet object not found for user", (int)ErrorCode.UNAUTHORIZED);
                    }

                    //update pet
                    ctx.pets.Attach(Pet);
                    Pet.breedId         = PetUpdateRequest.breedId;
                    Pet.birthDay        = PetUpdateRequest.birthDay;
                    Pet.coverImage      = PetUpdateRequest.coverImage;
                    Pet.isActive        = PetUpdateRequest.isActive;
                    Pet.lastUpdatedBy   = currentUser.username;
                    Pet.lastUpdatedTime = DateTime.Now;
                    Pet.petName         = PetUpdateRequest.petName;
                    Pet.profileImage    = PetUpdateRequest.profileImage;
                    Pet.sex             = PetUpdateRequest.sex;
                    ctx.SaveChanges();
                    logger.Trace("Successfully updated Pet id - " + Pet.id + " by - " + currentUser.username);
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
        }
Пример #4
0
        public PetWhizzResponse UpdatePet(PetUpdateRequest PetUpdateRequest)
        {
            PetWhizzResponse _oResponse;

            try
            {
                animalService.UpdatePet(PetUpdateRequest);
                _oResponse = Utils.CreateSuccessResponse(null);
            }
            catch (Exception ex)
            {
                _oResponse = Utils.CreateErrorResponse(ex);
            }
            return(_oResponse);
        }
        public void Update(PetUpdateRequest data, int userId)
        {
            if (data == null)
            {
                throw new ArgumentNullException("Parameter data is required");
            }

            string storedProc = "[dbo].[Pets_Update]";

            _dataProvider.ExecuteNonQuery(storedProc, delegate(SqlParameterCollection sqlParams)
            {
                sqlParams.AddWithValue("@Id", data.Id);
                sqlParams.AddWithValue("@UserId", userId);
                sqlParams.AddWithValue("@Name", data.Name);
                sqlParams.AddWithValue("@DOB", data.DOB);
                sqlParams.AddWithValue("@PrimaryPhotoUrl", data.PrimaryPhotoUrl);
                sqlParams.AddWithValue("@BreedId", data.BreedId);
                sqlParams.AddWithValue("@TotalPoints", data.TotalPoints);
                sqlParams.AddWithValue("@CurrentPoints", data.CurrentPoints);
                sqlParams.AddWithValue("@Weight", data.Weight);
                sqlParams.AddWithValue("@Appetite", data.Appetite);
            });
        }
Пример #6
0
        public PetTableModel MapUpdateRequestToTable(PetUpdateRequest request, PetTableModel petTable)
        {
            if (request.Name != null && !request.Name.Equals(petTable.Name))
            {
                petTable.Name = request.Name;
            }

            if (!request.SexType.Equals(petTable.SexType))
            {
                petTable.SexType = request.SexType;
            }

            if (request.DateOfBirth != null && !request.DateOfBirth.Equals(petTable.DateOfBirth))
            {
                petTable.DateOfBirth = request.DateOfBirth;
            }

            if (request.Description != null && !request.Description.Equals(petTable.Description))
            {
                petTable.Description = request.Description;
            }

            return(petTable);
        }
Пример #7
0
        public Pet UpdatePet(PetUpdateRequest request)
        {
            var response = _findMyPetClient.JsonClient().Put(request);

            return(response);
        }