public async Task <Guid> AddEvent(AddEventModel addEventModel, Guid personUid) { var eventUid = Guid.NewGuid(); var person = await _personRepository.GetPerson(personUid); var entity = _mapper.Map <EventEntity>(addEventModel); entity.EventUid = eventUid; entity.AdministratorId = person.PersonId; entity.Chat = new ChatEntity { ChatUid = Guid.NewGuid(), IsGroupChat = true }; entity.CreationTime = DateTime.UtcNow; var imageList = new List <EventImageContentEntity>(); if (addEventModel.PrimaryImage != null && addEventModel.PrimaryImage.Any()) { var eventImageContentUid = await _imageLogic.SaveImage(addEventModel.PrimaryImage); imageList.Add(new EventImageContentEntity { EventImageContentUid = eventImageContentUid, IsPrimary = true }); } if (addEventModel.Images != null) { foreach (var image in addEventModel.Images) { var eventImageContentUid = await _imageLogic.SaveImage(image); imageList.Add(new EventImageContentEntity { EventImageContentUid = eventImageContentUid, IsPrimary = false }); } } entity.EventImageContentEntities = imageList; await _eventRepository.CreateEvent(entity); await AddParticipant(new EventParticipantModel { EventUid = eventUid, PersonUid = person.PersonUid, ParticipantStatus = ParticipantStatus.Active }, personUid); return(eventUid); }
public async Task <ChatMessageModel> AddChatMessage(AddMessageModel request, Guid personUid) { var chatEntity = await _chatRepository.GetChat(request.ChatUid); var personEntity = await _personRepository.GetPerson(personUid); var chatMessageUid = Guid.NewGuid(); var date = DateTime.UtcNow; var messageEntity = new ChatMessageEntity { ChatMessageUid = chatMessageUid, Content = request.Content, MessageTime = date, ChatId = chatEntity.ChatId, AuthorId = personEntity.PersonId }; await _chatRepository.AddChatMessage(messageEntity); var chatImageUids = new List <Guid>(); foreach (var image in request.Images) { var chatImageUid = await _imageLogic.SaveImage(image); await _chatRepository.SaveChatImage(chatMessageUid, new ChatImageContentEntity { ChatImageContentUid = chatImageUid }); chatImageUids.Add(chatImageUid); } await _chatRepository.AddLastReadChatMessage(chatEntity, personUid, messageEntity.ChatMessageId); await SendPushNotificationsToChatMembers(chatEntity, personEntity, request.Content); return(new ChatMessageModel { Images = chatImageUids, MessageContent = request.Content, MessageUid = chatMessageUid, PersonUid = personEntity.PersonUid, PersonName = personEntity.Name, MessageTime = date, PersonImageUid = personEntity.PersonImageContentEntity?.PersonImageContentUid }); }
public async Task <PersonModel> UpdatePerson(UpdatePersonModel updatePersonModel, Guid personUid) { var entity = await _personRepository.GetPerson(personUid); if (!string.IsNullOrEmpty(updatePersonModel.Name)) { entity.Name = updatePersonModel.Name; } if (!string.IsNullOrEmpty(updatePersonModel.Description)) { entity.Description = updatePersonModel.Description; } if (updatePersonModel.Age.HasValue) { entity.Age = updatePersonModel.Age; } if (updatePersonModel.CityId.HasValue) { entity.CityId = updatePersonModel.CityId; } if (!string.IsNullOrEmpty(updatePersonModel.Login)) { entity.Login = updatePersonModel.Login; } if (string.IsNullOrWhiteSpace(entity.Login) && string.IsNullOrWhiteSpace(updatePersonModel.Login)) { entity.Login = await GenarateLogin(updatePersonModel.Name); } if (updatePersonModel.Token != null) { entity.Token = updatePersonModel.Token; await _personRepository.RemoveTokenForEveryPerson(updatePersonModel.Token); } var deleteOldImage = false; var imageToDelete = entity.PersonImageContentEntity; if (updatePersonModel.Image != null) { deleteOldImage = entity.PersonImageContentEntity != null; var imageUid = await _imageLogic.SaveImage(updatePersonModel.Image); var miniImageUid = await _imageLogic.SaveImage(updatePersonModel.MiniImage); entity.PersonImageContentEntity = new PersonImageContentEntity { PersonImageContentUid = imageUid, PersonMiniatureImageContentUid = miniImageUid }; } else { entity.PersonImageContentEntity = null; } var model = _mapper.Map <PersonModel>(entity); entity.FriendList = null; entity.City = null; entity.SwipeHistory = null; await _personRepository.UpdatePerson(entity); if (deleteOldImage) { await _personRepository.RemovePersonImage(imageToDelete); await _imageLogic.RemoveImage(imageToDelete.PersonImageContentUid); if (imageToDelete.PersonMiniatureImageContentUid.HasValue) { await _imageLogic.RemoveImage(imageToDelete.PersonMiniatureImageContentUid.Value); } } return(model); }