Пример #1
0
        public Conversation GetById_(Guid conversationId, Guid current)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                Database.Entities.Conversation dbConversation = unitOfWork.ConversationRepository.GetByID(conversationId);



                Guid otherUserId = current == dbConversation.FromID ? dbConversation.PetOwnerId : dbConversation.FromID;

                Database.Entities.UserDetails otherUser = unitOfWork.UserDetailsRepository.GetByID(otherUserId);
                Database.Entities.Pet         pet       = unitOfWork.PetRepository.GetByID(dbConversation.PetID);

                Conversation conversation = new Conversation()
                {
                    WithID         = dbConversation.FromID,
                    WithImagineUrl = otherUser.ImagineUrl, //sender.Image,
                    ID             = dbConversation.ID,
                    PetID          = dbConversation.PetID,
                    PetImagineUrl  = pet.ImageUrl,
                    YourId         = dbConversation.PetOwnerId,
                    YourImagineUrl = dbConversation.PetOwnerImagineUrl,
                    Active         = dbConversation.Status
                };

                return(conversation);
            }
        }
Пример #2
0
 public void Update(Database.Entities.Pet pet)
 {
     using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
     {
         unitOfWork.PetRepository.Update(pet);
         unitOfWork.Save();
     }
 }
Пример #3
0
 public void Delete(Guid id)
 {
     using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
     {
         Database.Entities.Pet pet = GetPet(id);
         unitOfWork.PetRepository.Delete(pet);
         unitOfWork.Save();
     }
 }
Пример #4
0
        public ActionResult Create(Database.Entities.Pet pet)
        {
            pet.ID = Guid.NewGuid();

            pet.OwnerID = new Guid(User.Identity.GetUserId());

            petService.AddOrUpdate(pet);

            return(RedirectToAction("List"));
        }
Пример #5
0
        public Conversation[] GetAllForUser(Guid userId)
        {
            using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
            {
                List <Conversation> conversations = new List <Conversation>();

                Database.Entities.Conversation[] dbConversations = unitOfWork.ConversationRepository.GetAllFor(userId);

                Guid[] otherUserIds = dbConversations.SelectMany(x => new Guid[2] {
                    x.FromID, x.PetOwnerId
                }).Distinct().ToArray();
                Guid[] petIds = dbConversations.Select(x => x.PetID).Distinct().ToArray();

                Database.Entities.UserDetails[] otherUsers = unitOfWork.UserDetailsRepository.GetByIds(otherUserIds);

                Database.Entities.Pet[] pets = unitOfWork.PetRepository.GetByIds(petIds);

                UserDetails yourDetails = otherUsers.First(x => x.ID == userId);

                foreach (Database.Entities.Conversation dbConversation in dbConversations)
                {
                    Guid otherUserId = userId == dbConversation.FromID ? dbConversation.PetOwnerId : dbConversation.FromID;

                    Database.Entities.UserDetails otherUser = otherUsers.First(x => x.ID == otherUserId);
                    Database.Entities.Pet         pet       = pets.FirstOrDefault(x => x.ID == dbConversation.PetID);

                    if (pet != null)
                    {
                        conversations.Add(new Conversation()
                        {
                            WithID         = dbConversation.FromID,
                            WithImagineUrl = otherUser.ImagineUrl, //sender.Image,
                            ID             = dbConversation.ID,
                            PetID          = dbConversation.PetID,
                            PetImagineUrl  = pet.ImageUrl,
                            YourId         = userId,
                            YourImagineUrl = yourDetails.ImagineUrl,
                            Active         = dbConversation.Status,
                            WithName       = otherUser.Name
                        });
                    }
                }

                return(conversations.ToArray());
            }
        }
Пример #6
0
 public Database.Entities.Conversation GetConversationBeetwen(Guid userId, Guid petId)
 {
     using (IUnitOfWork unitOfWork = unitOfWorkFactory.Create())
     {
         if (!unitOfWork.ConversationRepository.ExistsBetween(userId, petId))
         {
             Database.Entities.Pet          pet            = unitOfWork.PetRepository.GetByID(petId);
             UserDetails                    petOwner       = unitOfWork.UserDetailsRepository.GetByID(pet.OwnerID);
             UserDetails                    user           = unitOfWork.UserDetailsRepository.GetByID(userId);
             Database.Entities.Conversation dbConversation = new Database.Entities.Conversation()
             {
                 ID = Guid.NewGuid(), PetID = petId, PetOwnerId = pet.OwnerID, PetImagineUrl = pet.ImageUrl, FromID = userId
             };
             unitOfWork.ConversationRepository.Create(dbConversation);
             unitOfWork.Save();
             return(dbConversation);
         }
         return(unitOfWork.ConversationRepository.GetConversationBetween(userId, petId));
     }
 }
Пример #7
0
        public IHttpActionResult Post(Models.Pet pet)
        {
            Database.Entities.Pet dbPet = new Database.Entities.Pet()
            {
                ID          = Guid.NewGuid(),
                Adopted     = pet.Adopted,
                Name        = pet.Name,
                ImageUrl    = pet.ImageUrl,
                Description = pet.Description,
                BirthDate   = pet.BirthDate,
                Breed       = pet.Breed,
                FurType     = pet.FurType,
                Location    = pet.Location,
                MainColour  = pet.MainColour,
                PureBreed   = pet.PureBreed,
                Size        = pet.Size,
                Species     = pet.Species,
                OwnerID     = new Guid(User.Identity.GetUserId())
            };

            petService.Create(dbPet);

            return(Ok());
        }
Пример #8
0
 public ActionResult Edit(Database.Entities.Pet pet)
 {
     petService.AddOrUpdate(pet);
     return(RedirectToAction("Details", pet));
 }
Пример #9
0
 public ActionResult Edit(Guid id)
 {
     Database.Entities.Pet pet = petService.GetPet(id);
     return(View(pet));
 }
Пример #10
0
 public IHttpActionResult Put(Database.Entities.Pet pet)
 {
     petService.Update(pet);
     return(Ok());
 }
Пример #11
0
 public IHttpActionResult GetPet(Guid petId)
 {
     Database.Entities.Pet pet = petService.GetPet(petId);
     return(Ok(pet));
 }