Example #1
0
        public async Task <IUserRecommendationResponse> SendRecommendationAsync(MultipleUserRecommendationModelView view)
        {
            try
            {
                logger.Info($"{ GetType().Name}  {  ExtensionUtility.GetCurrentMethod() }  input: {view.ToJsonString()} UserIPAddress: { _userIPAddress.GetUserIP().Result }");

                var firstName = await _appDbContext.Profiles.Where(k => k.Id == view.SenderUserID).Select(k => k.FirstNameEn).FirstOrDefaultAsync();

                var lastName = await _appDbContext.Profiles.Where(k => k.Id == view.SenderUserID).Select(k => k.LastNameEn).FirstOrDefaultAsync();

                var userName = firstName + " " + lastName;

                var notifyText = view.isAskedRecommendation ? userName + " is asked for recommendation" : userName + " has sent to you recommendation";

                List <UserRecommendationModelView> UserRecommendViews = new List <UserRecommendationModelView>();

                foreach (int RecipientUserID in view.RecipientUserID)
                {
                    var data = new UserRecommendation()
                    {
                        SenderUserID          = view.SenderUserID,
                        RecipientUserID       = RecipientUserID,
                        RecommendationText    = view.RecommendationText,
                        isAskedRecommendation = view.isAskedRecommendation,
                        isRead     = false,
                        Created    = DateTime.Now,
                        CreatedBy  = userName,
                        Modified   = DateTime.Now,
                        ModifiedBy = userName
                    };

                    await _appDbContext.AddAsync(data);

                    await _appDbContext.SaveChangesAsync();


                    var userRecommend = _mapper.Map <UserRecommendationModelView>(data);



                    //var deviceIds = await _appDbContext.UserDeviceInfos.Where(k => k.UserId == RecipientUserID).Select(k => k.DeviceId).ToListAsync();

                    //if (deviceIds.Count > 0)
                    //{
                    //    foreach (var deviceId in deviceIds)
                    //    {
                    //        logger.Info($"{ GetType().Name}  {  ExtensionUtility.GetCurrentMethod() }  Sending recommend push notification to User : {RecipientUserID} and Device ID: {deviceId} ");
                    //        await _pushNotificationService.SendRecommendPushNotificationAsync(userRecommend, notifyText, deviceId);
                    //    }
                    //    logger.Info("Notification sent");
                    //}

                    var customNotificationData = await _appDbContext.CustomNotifications.Where(x => x.ProfileID == data.RecipientUserID && x.CategoryID == (int)CategoryType.Messages).FirstOrDefaultAsync();

                    if (customNotificationData?.isEnabled == true || customNotificationData == null)
                    {
                        await AddNotificationAsync(data.RecipientUserID, data.isAskedRecommendation?ActionType.AskRecommendation : ActionType.SendRecommendation, data.ID, ParentType.UserRecommendation, data.SenderUserID, notifyText);
                    }

                    UserRecommendViews.Add(userRecommend);
                }

                return(new UserRecommendationResponse(UserRecommendViews));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(new UserRecommendationResponse(ex));
            }
        }
Example #2
0
        public async Task <IActionResult> SendRecommendationAsync([FromBody] MultipleUserRecommendationModelView view)
        {
            var result = await _userRecommendationService.SendRecommendationAsync(view);

            return(Ok(result));
        }