public async Task <bool> RemovePhoto(Language language, int id) { var homePageImages = await _repository.GetAll <HomePageCoverImage>() .OrderByDescending(x => x.CreatedDt).ToListAsync(); var homePageImage = await _repository.FilterAsNoTracking <HomePageCoverImage>(x => x.Id == id).FirstOrDefaultAsync(); if (homePageImage == null) { throw new Exception("configuration not found"); } if (homePageImages.Count == 1) { throw new Exception(_optionsBinder.Error().UploadAnotherPhoto); } await _accessor.Remove(homePageImage.Photo, UploadType.HomePageCoverImage); if (homePageImage.IsBase) { _repository.HardDelete(homePageImage); var lastOrDefault = homePageImages.FirstOrDefault(x => !x.IsBase); lastOrDefault.IsBase = true; _repository.Update(lastOrDefault); return(true); } _repository.HardDelete(homePageImage); await _repository.SaveChangesAsync(); return(true); }
public async Task <bool> SubscribeAsync(AddSubscribeRequestModel model, int userId, string deviceId, Language language) { Guest guest = null; SubscribeAnnouncement subscribeAnnouncement = null; var user = await repository.FilterAsNoTracking <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (user == null) { guest = await repository.FilterAsNoTracking <Guest>(g => g.DeviceId == deviceId).FirstOrDefaultAsync(); if (guest == null) { throw new Exception(optionsBinder.Error().NoGuest); } } var announcement = await repository.FilterAsNoTracking <Announcement>(a => a.Id == model.AnnouncementId).FirstOrDefaultAsync(); if (announcement == null) { throw new Exception(optionsBinder.Error().AnnouncementNotFound); } if (user != null) { subscribeAnnouncement = await repository.Filter <SubscribeAnnouncement>(s => s.UserId == user.Id && s.AnnouncementId == announcement.Id).FirstOrDefaultAsync(); } else { subscribeAnnouncement = await repository.Filter <SubscribeAnnouncement>(s => s.GuestId == guest.Id && s.AnnouncementId == announcement.Id).FirstOrDefaultAsync(); } if (subscribeAnnouncement != null) { throw new Exception("Subscribe Announcement already exist"); } repository.Create(new SubscribeAnnouncement { User = user ?? null, Guest = guest ?? null, AnnouncementId = announcement.Id, Email = model.Email, Address = announcement.AddressEn, AnnouncementType = announcement.AnnouncementType, AnnouncementEstateType = announcement.AnnouncementEstateType }); await repository.SaveChangesAsync(); return(true); }
public async Task <int> Add(int announcementId, int userId) { var caller = await _repository.Filter <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (caller == null) { throw new Exception("caller not found"); } var announcement = await _repository .Filter <Announcement>(x => !x.IsDraft && x.UserId != caller.Id && x.Id == announcementId).FirstOrDefaultAsync(); if (announcement == null) { throw new Exception(_optionsBinder.Error().AnnouncementNotFound); } var conversation = await _repository.Filter <Conversation>(c => c.AnnouncementCreatorId == announcement.UserId && c.AnnouncementId == announcement.Id && c.QuestionerId == caller.Id).FirstOrDefaultAsync(); if (conversation != null) { conversation.QuestionerConversationIsDeleted = false; conversation.AnnouncementCreatorConversationIsDeleted = false; _repository.Update(conversation); } else { conversation = _repository.Create(new Conversation { AnnouncementCreatorId = announcement.UserId, AnnouncementId = announcement.Id, QuestionerId = caller.Id }); } await _repository.SaveChangesAsync(); return(conversation.Id); }
public async Task <MessageListModel> Send(SendMessageModel model, int userId, Language language, string deviceId) { string sentMessage; var caller = await _repository.Filter <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (caller == null) { throw new Exception("caller not found"); } var conversation = await _repository.Filter <Conversation>(x => x.Id == model.ConversationId) .FirstOrDefaultAsync(); if (conversation.AnnouncementCreatorId != caller.Id && conversation.QuestionerId != caller.Id) { throw new Exception(_optionsBinder.Error().NotParticipating); } if (conversation.AnnouncementCreatorConversationIsDeleted || conversation.QuestionerConversationIsDeleted) { conversation.QuestionerConversationIsDeleted = false; conversation.AnnouncementCreatorConversationIsDeleted = false; _repository.Update(conversation); } var body = model.MessageText; var messageBodyType = MessageBodyType.Text; long length = 0; if (model.File != null) { messageBodyType = MessageBodyType.Image; body = await _accessor.Upload(model.File, UploadType.MessageFiles, conversation.Id); var extension = Path.GetExtension(body); if (extension != ".jpg" && extension != ".jpeg" && extension != ".png") { messageBodyType = MessageBodyType.File; } length = await _accessor.GetLength(body, UploadType.MessageFiles, conversation.Id); } int?replayValue = null; var receiverId = conversation.AnnouncementCreatorId == caller.Id ? conversation.QuestionerId : conversation.AnnouncementCreatorId; var message = _repository.Create(new Message { ConversationId = conversation.Id, MessageBodyType = messageBodyType, MessageText = body, SenderId = caller.Id, FileLength = length, ReciverId = receiverId, ReplayMessageId = model.ReplayMessageId.HasValue ? model.ReplayMessageId.Value : replayValue }); await _repository.SaveChangesAsync(); int unreadConversationCount = _repository.Filter <Message>(m => m.ReciverId == receiverId && !m.IsSeen).GroupBy(m => m.ConversationId).Count(); var success = _repository.FilterAsNoTracking <PersonSetting>(x => x.UserId == receiverId).Where(x => x.SubscriptionsType == SubscriptionsType.EnableMessageNotification).Count(); var notify = (new MessageListModel { SenderId = caller.Id, FullName = message.User != null ? message.User.FullName : "User", Photo = message.User != null ? new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, message.User.ProfilePhoto, ConstValues.Width, ConstValues.Height, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, message.User.ProfilePhoto, 100, 100, true, 0) } : new ImageOptimizer(), CreatedDate = new DateTime(message.CreatedDt.Ticks), IsSentFromMe = false, MessageId = message.Id, MessageBodyType = messageBodyType, MessageText = message.MessageBodyType == MessageBodyType.Image ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.MessageFiles, message.MessageText, 200, 200, false, conversation.Id) : message.MessageText, FileSize = length, FileUrl = messageBodyType == MessageBodyType.File ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaDownload, UploadType.MessageFiles, message.MessageText, false, conversation.Id) : null, ReplayMessage = message.ReplayMessageId != null ? await _repository.Filter <Message>(s => s.Id == message.ReplayMessageId) .Select(s => new MessageListModel { MessageBodyType = s.MessageBodyType, Photo = s.User != null ? new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, s.User.ProfilePhoto, ConstValues.Width, ConstValues.Height, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, s.User.ProfilePhoto, 100, 100, true, 0) } : new ImageOptimizer(), SenderId = s.SenderId, FullName = s.User != null ? s.User.FullName : "User", MessageId = s.Id, MessageText = s.MessageBodyType == MessageBodyType.Image ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.MessageFiles, s.MessageText, 1000, 1000, false, conversation.Id) : s.MessageText, CreatedDate = s.CreatedDt, IsSentFromMe = s.SenderId == caller.Id, FileUrl = s.MessageBodyType == MessageBodyType.File ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaDownload, UploadType.MessageFiles, s.MessageText, false, conversation.Id) : null, FileSize = s.FileLength }).FirstOrDefaultAsync() : null }); var ann = _repository.Filter <Announcement>(a => a.Id == model.AnnouncementId).FirstOrDefault(); if (ann != null) { await _activityService.AddOrUpdate(ann, caller.Id, false, ActivityType.Contacted); } var notifyToString = Utilities.SerializeObject(notify); var isSent = await ChatMessageHandler.SendMessageAsync(conversation.Id, caller.Id, notifyToString, deviceId); if (isSent) { message.IsSeen = true; await _repository.SaveChangesAsync(); } if (!isSent) { var receiverLanguage = await _repository.Filter <PersonOtherSetting>(x => x.UserId == receiverId) .Select(x => x.Language).FirstOrDefaultAsync(); if (receiverLanguage == Language.English) { sentMessage = "sent you a message"; } else { sentMessage = "ارسلت لك رساله"; } await BaseMessageHandler.SendMessageAsync(conversation.Id, receiverId); if (success > 0) { await _firebaseRepository.SendIndividualNotification(new NewMessageNotificationModel { SenderId = caller.Id, Description = messageBodyType == MessageBodyType.Image ? "Image" : messageBodyType == MessageBodyType.File ? "Photo" : model.MessageText, GenericId = conversation.Id, NotificationType = NotificationType.NewMessage, ReceiverId = receiverId, Title = $"{caller.FullName} {sentMessage}", UnreadConversationCount = unreadConversationCount }, false); } await _firebaseRepository.SendIndividualNotification(new NewMessageNotificationModel { SenderId = caller.Id, Description = messageBodyType == MessageBodyType.Image ? "Image" : messageBodyType == MessageBodyType.File ? "Photo" : model.MessageText, GenericId = conversation.Id, NotificationType = NotificationType.NewMessageGeneralInformation, ReceiverId = receiverId, Title = $"{caller.FullName} {sentMessage}", UnreadConversationCount = unreadConversationCount }, false); } return(notify); }
public async Task <bool> Add(AddSaveFilterViewModel model, int userId, Language language, string deviceId) { SaveFilter saveFilter = new SaveFilter(); Guest guest = new Guest(); var user = await _repository.FilterAsNoTracking <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (user == null) { guest = await _repository.FilterAsNoTracking <Guest>(g => g.DeviceId == deviceId).FirstOrDefaultAsync(); if (guest == null) { throw new Exception(_optionsBinder.Error().UserNotFound); } saveFilter.GuestId = guest.Id; } else { saveFilter.UserId = user.Id; } var filterCount = 0; if (string.IsNullOrEmpty(model.SaveFilterName)) { throw new Exception(_optionsBinder.Error().FilterName); } if (!string.IsNullOrEmpty(model.Search)) { saveFilter.Search = model.Search; filterCount += 1; } if (model.AnnouncementType.HasValue) { if (saveFilter.Description == null) { saveFilter.Description = model.AnnouncementType.ToString(); } saveFilter.AnnouncementType = model.AnnouncementType; filterCount += 1; } if (model.AnnouncementEstateType.HasValue) { if (saveFilter.Description == null) { saveFilter.Description = model.AnnouncementEstateType.ToString(); } saveFilter.AnnouncementEstateType = model.AnnouncementEstateType; filterCount += 1; } if (model.AnnouncementRentType.HasValue) { saveFilter.AnnouncementRentType = model.AnnouncementRentType; filterCount += 1; } if (model.AnnouncementResidentialType.HasValue) { saveFilter.AnnouncementResidentialType = model.AnnouncementResidentialType; filterCount += 1; } if (model.LandType.HasValue) { saveFilter.LandType = model.LandType; filterCount += 1; } if (model.ConstructionStatus.HasValue) { saveFilter.ConstructionStatus = model.ConstructionStatus; filterCount += 1; } if (model.LandCategory.HasValue) { saveFilter.LandCategory = model.LandCategory; filterCount += 1; } if (model.FurnishingStatus.HasValue) { saveFilter.FurnishingStatus = model.FurnishingStatus; filterCount += 1; } if (model.SaleType.HasValue) { saveFilter.SaleType = model.SaleType; filterCount += 1; } if (model.BuildingAge.HasValue) { saveFilter.BuildingAge = model.BuildingAge; filterCount += 1; } if (model.CommercialType.HasValue) { saveFilter.CommercialType = model.CommercialType; filterCount += 1; } if (model.FacadeType.HasValue) { saveFilter.FacadeType = model.FacadeType; filterCount += 1; } if (model.OwnerShip.HasValue) { saveFilter.OwnerShip = model.OwnerShip; filterCount += 1; } if (model.SittingCount.HasValue) { saveFilter.SittingCount = model.SittingCount; filterCount += 1; } if (model.CountryId.HasValue) { saveFilter.CountryId = model.CountryId; saveFilter.CountryName = model.CountryName; filterCount += 1; } if (model.CityId.HasValue) { saveFilter.CityId = model.CityId; saveFilter.CityName = model.CityName; filterCount += 1; } if (model.PriceFrom > 0 || model.PriceTo > 0) { saveFilter.PriceTo = model.PriceTo; saveFilter.PriceFrom = model.PriceFrom; filterCount += 1; } if (model.MinArea > 0 || model.MaxArea > 0) { saveFilter.MinArea = model.MinArea; saveFilter.MaxArea = model.MaxArea; filterCount += 1; } if (model.MaxMeterPrice.HasValue || model.MinMeterPrice.HasValue) { saveFilter.MinMeterPrice = model.MinMeterPrice; saveFilter.MaxMeterPrice = model.MaxMeterPrice; filterCount += 1; } if (model.BathroomCount != 0 && model.BathroomCount.HasValue) { saveFilter.BathroomCount = model.BathroomCount; filterCount += 1; } if (model.BedroomCount != 0 && model.BedroomCount.HasValue) { saveFilter.BedroomCount = model.BedroomCount; filterCount += 1; } saveFilter.SaveFilterName = model.SaveFilterName; if (model.Features.Count() != 0) { foreach (var item in model.Features) { _repository.Create(new SaveFilterFeature { FeatureType = item, SaveFilter = saveFilter }); } filterCount += 1; } saveFilter.FilterCount = filterCount; await _repository.CreateAsync(saveFilter); await _repository.SaveChangesAsync(); return(true); }
public async Task <PagingResponseModel <SupportConversationListModel> > GetList(SupportConversationPagingRequestModel model, int userId) { var caller = await _repository.FilterAsNoTracking <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (caller == null) { throw new Exception(_optionsBinder.Error().UserNotFound); } var query = _repository.Filter <SupportConversation>(sp => sp.SupportMessages.Count(s => !s.IsDeleted) > 0); //if (!string.IsNullOrEmpty(model.Search)) //{ // //model.Search = model.Search.ToLower(); // var searchParams = model.Search.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); // foreach (var variable in searchParams) // { // query = query.Where(x => // x.UserId != null // ? x.User.FullName.ToLower().Contains(variable) : x.GuestId.Value.ToString().Contains(variable)); // } //} if (!string.IsNullOrEmpty(model.Search)) { //var searchParams = model.Search.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); //foreach (var variable in searchParams) //{ // query = query.Where(x => // x.UserId != null // ? x.User.FullName.ToLower().Contains(variable) : x.GuestId.Value.ToString().Contains(variable)); //} query = query.Where(sp => sp.UserId != null ? sp.User.FullName.Contains(model.Search) : sp.GuestId.ToString().Contains(model.Search)); } var count = await query.CountAsync(); var page = Convert.ToInt32(Math.Ceiling(decimal.Divide(count, model.Count))); var result = await query.Skip((model.Page - 1) *model.Count).Take(model.Count) .OrderByDescending(x => x.SupportMessages.OrderByDescending(s => s.CreatedDt).Select(s => s.CreatedDt).FirstOrDefault()) .Select(x => new SupportConversationListModel { Id = x.Id, FullName = x.User != null ? x.User.FullName : $"Guest N {x.GuestId}", SupportMessageBodyType = x.SupportMessages.OrderByDescending(s => s.CreatedDt) .Select(s => s.SupportMessageBodyType) .FirstOrDefault(), MessageText = x.SupportMessages.OrderByDescending(s => s.CreatedDt).Select(s => s.MessageText) .FirstOrDefault(), UnSeenCount = x.SupportMessages.Where(s => s.UserSenderId != caller.Id).Count(s => !s.IsSeen), Photo = x.User != null ? new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, x.User.ProfilePhoto, 300, 300, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, x.User.ProfilePhoto, 100, 100, true, 0) } : new ImageOptimizer() }).ToListAsync(); foreach (var variable in result) { if (variable.SupportMessageBodyType == SupportMessageBodyType.Message) { continue; } variable.MessageText = variable.SupportMessageBodyType == SupportMessageBodyType.Photo ? "Sent Photo" : variable.SupportMessageBodyType == SupportMessageBodyType.Announcement ? "Sent Announcement" : "Sent Image"; } return(new PagingResponseModel <SupportConversationListModel> { PageCount = page, DateFrom = null, ItemCount = count, Data = result }); }
public async Task <bool> SendKeyAsync(SendKeyModel model, Language language) { var key = Utilities.KeyGenerator(4); string bodyText; string subject; if (language == Language.English) { bodyText = "Your verification key is"; subject = "Baitkm Registration code"; } else { subject = "رمز تسجيل منزلك"; bodyText = "مفتاح التحقق الخاص بك هو"; } var user = await _repository.FilterAsNoTracking <User>(u => (u.Email == model.VerificationTerm && u.VerifiedBy == VerifiedBy.Email) || (u.PhoneCode == model.PhoneCode && u.Phone == model.VerificationTerm && u.VerifiedBy == VerifiedBy.Phone)).FirstOrDefaultAsync(); if (user != null) { throw new Exception(_optionsBinder.Error().AccountExist); } var verified = await _repository.Filter <Verified>(v => v.Email == model.VerificationTerm && v.VerifiedBy == VerifiedBy.Email || (v.PhoneCode == model.PhoneCode && v.Phone == model.VerificationTerm && v.VerifiedBy == VerifiedBy.Phone)).FirstOrDefaultAsync(); if (verified != null) { if (verified.IsRegistered) { throw new Exception(_optionsBinder.Error().AccountExist); } } if (Regex.Replace(model.VerificationTerm, @"\s+", "").All(c => Char.IsDigit(c))) { if (verified != null) { verified.Code = key; _repository.Update(verified); } else { _repository.Create(new Verified { PhoneCode = model.PhoneCode, Phone = model.VerificationTerm, Code = key, VerifiedBy = VerifiedBy.Phone }); } Utilities.SendKeyByTwilio(model.PhoneCode + model.VerificationTerm, key, bodyText); } else { if (verified != null) { verified.Code = key; _repository.Update(verified); } else { _repository.Create(new Verified { Email = model.VerificationTerm, Code = key, VerifiedBy = VerifiedBy.Email }); } Utilities.SendKeyByEmail(model.VerificationTerm, key, subject, bodyText); } await _repository.SaveChangesAsync(); return(true); }
public async Task <SupportMessageListModel> Send(SendSupportMessageModel model, int userId, Language language, string deviceId) { //User caller = null; Guest guest = null; var caller = await _repository.FilterAsNoTracking <User>(u => u.Id == userId).FirstOrDefaultAsync(); if (caller == null) { guest = await _repository.FilterAsNoTracking <Guest>(g => g.DeviceId == deviceId).FirstOrDefaultAsync(); if (guest == null) { throw new Exception(_optionsBinder.Error().UserNotFound); } } var conversation = await _repository.Filter <SupportConversation>(x => x.Id == model.ConversationId) .FirstOrDefaultAsync(); if (conversation == null) { throw new Exception("connversation not found"); } var body = model.MessageText; var messageBodyType = model.SupportMessageBodyType; long length = 0; if (model.File != null) { messageBodyType = SupportMessageBodyType.Image; body = await _accessor.Upload(model.File, UploadType.SupportConversationFiles, conversation.Id); var extension = Path.GetExtension(body); if (extension != ".jpg" && extension != ".jpeg" && extension != ".png") { messageBodyType = SupportMessageBodyType.Photo; } length = await _accessor.GetLength(body, UploadType.SupportConversationFiles, conversation.Id); } int?replayValue = null; var supportMessage = new SupportMessage { SupportConversationId = conversation.Id, SupportMessageBodyType = messageBodyType, MessageText = body, FileLength = length, ReplayMessageId = model.ReplayMessageId.HasValue ? model.ReplayMessageId.Value : replayValue }; if (caller != null) { supportMessage.UserSenderId = caller.Id; supportMessage.GuestSenderId = null; } else { supportMessage.GuestSenderId = guest.Id; supportMessage.UserSenderId = null; } _repository.Create(supportMessage); await _repository.SaveChangesAsync(); int receiverId; if (caller != null) { receiverId = conversation.AdminId == caller.Id ? conversation.GuestId ?? conversation.UserId ?? 0 : conversation.AdminId; } else { receiverId = conversation.AdminId; } var isGuest = conversation.GuestId != null; var callerId = caller?.Id ?? guest.Id; AnnouncementListViewModel announcement = null; if (messageBodyType == SupportMessageBodyType.Announcement) { int.TryParse(model.MessageText, out var id); announcement = await _repository.Filter <Announcement>(x => !x.IsDraft && x.Id == id).Select(x => new AnnouncementListViewModel { Id = x.Id, BathroomCount = x.BathroomCount, AnnouncementResidentialType = x.AnnouncementResidentialType, AnnouncementRentType = x.AnnouncementRentType, IsFavourite = false, Address = x.AddressEn.Trim(), AnnouncementEstateType = x.AnnouncementEstateType, AnnouncementType = x.AnnouncementType, Area = Convert.ToInt64(x.Area), BedroomCount = x.BedroomCount, Price = Convert.ToInt64(x.Price), Title = x.Title, CreateDate = x.CreatedDt, Photo = new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.AnnouncementBasePhoto, x.BasePhoto, 300, 300, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.AnnouncementBasePhoto, x.BasePhoto, 100, 100, true, 0) } }).FirstOrDefaultAsync(); } var notify = (new SupportMessageListModel { ConversationId = conversation.Id, MessageId = supportMessage.Id, MessageText = supportMessage.SupportMessageBodyType == SupportMessageBodyType.Image ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.SupportConversationFiles, supportMessage.MessageText, 1000, 1000, false, conversation.Id) : supportMessage.MessageText, MessageBodyType = messageBodyType, SenderId = caller?.Id ?? guest.Id, FullName = caller != null ? supportMessage.UserSender.FullName : guest.Id.ToString(), Photo = caller != null ? new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, supportMessage.UserSender.ProfilePhoto, ConstValues.Width, ConstValues.Height, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, supportMessage.UserSender.ProfilePhoto, 100, 100, true, 0) } : new ImageOptimizer(), CreatedDate = supportMessage.CreatedDt, IsSentFromMe = false, Announcement = announcement, FileSize = length, FileUrl = messageBodyType == SupportMessageBodyType.Photo ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaDownload, UploadType.SupportConversationFiles, supportMessage.MessageText, false, conversation.Id) : null, ReplayMessage = supportMessage.ReplayMessageId != null ? await _repository.Filter <SupportMessage>(s => s.Id == supportMessage.ReplayMessageId) .Select(s => new SupportMessageListModel { MessageBodyType = s.SupportMessageBodyType, MessageId = s.Id, MessageText = s.SupportMessageBodyType == SupportMessageBodyType.Image ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.SupportConversationFiles, s.MessageText, 1000, 1000, false, conversation.Id) : s.MessageText, CreatedDate = s.CreatedDt, IsSentFromMe = (s.UserSenderId ?? s.GuestSenderId ?? 0) == callerId, Photo = s.UserSender != null ? new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, s.UserSender.ProfilePhoto, ConstValues.Width, ConstValues.Height, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.ProfilePhoto, s.UserSender.ProfilePhoto, 100, 100, true, 0) } : new ImageOptimizer(), SenderId = s.UserSenderId ?? s.GuestSenderId.GetValueOrDefault(), FullName = s.UserSenderId != null ? s.UserSender.FullName : "User", FileUrl = s.SupportMessageBodyType == SupportMessageBodyType.Photo ? Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaDownload, UploadType.SupportConversationFiles, s.MessageText, false, conversation.Id) : null, FileSize = s.FileLength }).FirstOrDefaultAsync() : null }); if (notify.ReplayMessage != null && notify.ReplayMessage.MessageBodyType == SupportMessageBodyType.Announcement) { int.TryParse(notify.ReplayMessage.MessageText, out var replayMessage); notify.ReplayMessage.Announcement = _repository.Filter <Announcement>(x => !x.IsDraft && x.Id == replayMessage) .Select(x => new AnnouncementListViewModel { Id = x.Id, BathroomCount = x.BathroomCount, AnnouncementResidentialType = x.AnnouncementResidentialType, AnnouncementRentType = x.AnnouncementRentType, IsFavourite = false, Address = x.AddressEn.Trim(), AnnouncementEstateType = x.AnnouncementEstateType, AnnouncementType = x.AnnouncementType, Area = Convert.ToInt64(x.Area), BedroomCount = x.BedroomCount, Price = Convert.ToInt64(x.Price), Title = x.Title, Photo = new ImageOptimizer { Photo = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.AnnouncementBasePhoto, x.BasePhoto, 300, 300, false, 0), PhotoBlur = Utilities.ReturnFilePath(ConstValues.MediaBaseUrl, ConstValues.MediaResize, UploadType.AnnouncementBasePhoto, x.BasePhoto, 100, 100, true, 0) } }).FirstOrDefault(); } var notifyToString = Utilities.SerializeObject(notify); var isSent = await SupportChatMessageHandler.SendMessageAsync(conversation.Id, receiverId, notifyToString, receiverId == conversation.GuestId); bool enableNotification = true; notify.IsSentFromMe = true; if (receiverId == conversation.AdminId && !isSent) { await SupportBaseMessageHandler.SendMessageAsync(conversation.Id, conversation.AdminId); return(notify); } if (!isSent && receiverId != conversation.AdminId) { if (isGuest && receiverId != conversation.AdminId) { enableNotification = _repository.FilterAsNoTracking <PersonSetting>(s => s.GuestId == receiverId) .Select(s => s.SubscriptionsType).Contains(SubscriptionsType.EnableMessageNotification); } else if (!isGuest && caller != null && receiverId != conversation.AdminId) { enableNotification = _repository.FilterAsNoTracking <PersonSetting>(s => s.UserId == receiverId) .Select(s => s.SubscriptionsType).Contains(SubscriptionsType.EnableMessageNotification); } if (enableNotification) { await _firebaseRepository.SendIndividualNotification(new NewMessageNotificationModel { SenderId = caller?.Id ?? guest.Id, Description = messageBodyType == SupportMessageBodyType.Image ? "Image" : messageBodyType == SupportMessageBodyType.Photo ? "Photo" : messageBodyType == SupportMessageBodyType.Announcement ? "Announcement" : model.MessageText, GenericId = conversation.Id, NotificationType = NotificationType.SupportMessage, ReceiverId = receiverId, Title = caller != null ? $"{caller.FullName} sent you a message" : $"Guest N {guest.Id} sent you a message" }, isGuest); } } return(notify); }
public async Task <bool> AddGuestAsync(string deviceId, string deviceToken, OsType osType, Language language, string currencyCode) { Currency currency = _repository.Filter <Currency>(c => c.Code == currencyCode && !c.IsDeleted).FirstOrDefault(); if (string.IsNullOrEmpty(deviceId)) { throw new Exception(_optionsBinder.Error().RequiredParameters); } var guest = await _repository.Filter <Guest>(x => x.DeviceId == deviceId).FirstOrDefaultAsync(); if (guest != null) { var otherSetting = await _repository.Filter <PersonOtherSetting>(x => x.GuestId == guest.Id).FirstOrDefaultAsync(); if (otherSetting != null) { otherSetting.Language = language; otherSetting.AreaUnit = AreaUnit.SquareMeter; _repository.Update(otherSetting); } else { await _repository.CreateAsync(new PersonOtherSetting { GuestId = guest.Id, Language = language, AreaUnit = AreaUnit.SquareMeter }); } await _repository.SaveChangesAsync(); return(true); } else if (guest == null) { var newGuest = _repository.Create(new Guest { DeviceId = deviceId, OsType = osType, Token = deviceToken, CurrencyId = currency.Id }); foreach (SubscriptionsType variable in Enum.GetValues(typeof(SubscriptionsType))) { if (variable == SubscriptionsType.PhoneNumberVisibility) { continue; } _repository.Create(new PersonSetting { GuestId = newGuest.Id, SubscriptionsType = variable }); } _repository.Create(new PersonOtherSetting { GuestId = newGuest.Id, AreaUnit = AreaUnit.SquareMeter, Language = language }); } await _repository.SaveChangesAsync(); return(true); }