public PetWhizzResponse GetUsersByPet(PetUserRequest PetUserRequest) { PetWhizzResponse _oResponse; try { PetUserResponse PetUserResponse = animalService.GetUsersByPet(PetUserRequest); _oResponse = Utils.CreateSuccessResponse(PetUserResponse); } catch (Exception ex) { _oResponse = Utils.CreateErrorResponse(ex); } return(_oResponse); }
internal PetUserResponse GetUsersByPet(PetUserRequest petUserRequest) { logger.Trace("Recived Get Users By Pet request"); PetUserResponse PetUserResponse = new PetUserResponse(); try { CurrentUser currentUser = (CurrentUser)HttpContext.Current.User; if (petUserRequest.petId <= 0) { logger.Error("Get users by pet petId is invalid"); throw new CustomException("Get users by pet petId is invalid", (int)ErrorCode.VALIDATIONFAILED); } using (var ctx = new PetWhizzEntities()) { pet Pet = ctx.pets.Where(a => a.id == petUserRequest.petId).FirstOrDefault(); if (Pet == null) { logger.Error("No pet found for given Id"); throw new CustomException("No pet found for given Id", (int)ErrorCode.NORECORDFOUND); } List <petOwner> petOwnerList = Pet.petOwners.Where(a => a.userId != currentUser.userId).ToList(); PetUserResponse.PetUserList = new List <PetUser>(); foreach (petOwner owner in petOwnerList) { PetUserResponse.userCount++; PetUser PetUser = new PetUser() { isConfirmed = owner.isActive, profilePic = owner.user.profilePic, userId = owner.userId, userName = owner.user.userName }; PetUserResponse.PetUserList.Add(PetUser); } } } 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(PetUserResponse); }