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

            try
            {
                animalService.PetEnrollment(PetEnrollmentRequest);
                _oResponse = Utils.CreateSuccessResponse(null);
            }
            catch (Exception ex)
            {
                _oResponse = Utils.CreateErrorResponse(ex);
            }
            return(_oResponse);
        }
Пример #2
0
        internal void PetEnrollment(PetEnrollmentRequest petEnrollmentRequest)
        {
            logger.Trace("Recived pet enroll request");
            try
            {
                CurrentUser currentUser = (CurrentUser)HttpContext.Current.User;
                if (String.IsNullOrEmpty(petEnrollmentRequest.petName) || petEnrollmentRequest.breedId == 0)
                {
                    logger.Error("Required fiedls not found on pet emrollment reuest");
                    throw new CustomException("Breed or Pet Name is empty", (int)ErrorCode.VALIDATIONFAILED);
                }
                //creating pet object
                pet Pet = new pet()
                {
                    profileImage = petEnrollmentRequest.profileImage,
                    coverImage   = petEnrollmentRequest.coverImage,
                    sex          = petEnrollmentRequest.sex,
                    birthDay     = petEnrollmentRequest.birthDay,
                    breedId      = petEnrollmentRequest.breedId,
                    entryDate    = DateTime.Now,
                    isActive     = true,
                    isDeleted    = false,
                    petName      = petEnrollmentRequest.petName
                };
                using (var ctx = new PetWhizzEntities())
                {
                    using (var dbContextTransaction = ctx.Database.BeginTransaction())
                    {
                        try
                        {
                            ctx.pets.Add(Pet);
                            ctx.SaveChanges();

                            petOwner PetOwner = new petOwner()
                            {
                                enteryDate  = DateTime.Now,
                                petId       = Pet.id,
                                userId      = currentUser.userId,
                                isActive    = true,
                                isMainOwner = true
                            };
                            ctx.petOwners.Add(PetOwner);
                            ctx.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                            logger.Error("DB error occure when enrolling Pet");
                            throw new CustomException("Pet Enrolling failed", (int)ErrorCode.PROCEESINGERROR);
                        }
                    }
                }
            }
            catch (CustomException) { throw; }
            catch (Exception ex)
            {
                logger.Error(MethodBase.GetCurrentMethod().Name + ": exception: " + ex.Message + ", " + ex.InnerException);
                throw new CustomException("SystemError", ex, (int)ErrorCode.PROCEESINGERROR);
            }
        }