Пример #1
0
        public PetWhizzResponse Pets()
        {
            PetWhizzResponse _oResponse;

            try
            {
                PetsResponse PetsResponse = animalService.Pets();
                _oResponse = Utils.CreateSuccessResponse(PetsResponse);
            }
            catch (Exception ex)
            {
                _oResponse = Utils.CreateErrorResponse(ex);
            }
            return(_oResponse);
        }
Пример #2
0
        internal PetsResponse Pets()
        {
            PetsResponse PetsResponse = new PetsResponse();

            logger.Trace("Recived get pets request");
            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;

                using (var ctx = new PetWhizzEntities())
                {
                    PetsResponse.petList = ctx.petOwners
                                           .Where(a => a.userId == currentUser.userId && a.isActive == true)
                                           .Select(b => new
                    {
                        b.pet.id,
                        b.pet.petName,
                        birthDay = b.pet.birthDay.ToString(),
                        b.pet.breedId,
                        b.pet.sex,
                        b.pet.animalBreed.breedName,
                        b.pet.animalBreed.animal.animalName,
                        b.pet.profileImage,
                        b.pet.coverImage,
                        b.pet.isActive,
                        b.pet.isDeleted,
                        userCount = b.pet.petOwners.Count
                    }).ToArray();
                };
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
            return(PetsResponse);
        }