public async Task <CommandResult <UserRecommendation> > ExecuteAsync(string idService)
        {
            try
            {
                var current = DateTime.Now;
                var userId  = _httpConextAccessor.HttpContext.User.Identity.Name;
                if (string.IsNullOrEmpty(userId))
                {
                    return(new CommandResult <UserRecommendation> {
                        isValid = false,
                        errorMessage = "Cannot find this user"
                    });
                }
                var findLatestTime = await _userRecommendation.
                                     FindAllAsync(x => x.UserId == Guid.Parse(userId) && x.ServiceId == Guid.Parse(idService));

                if (findLatestTime.Any())
                {
                    var getNearestTime      = findLatestTime.OrderByDescending(x => x.DateCreated).FirstOrDefault().DateCreated;
                    var subtractLatestDate  = current.Subtract(getNearestTime);
                    var subtractDefaultDate = current.Subtract(current.AddMinutes(-15));
                    if (subtractLatestDate < subtractDefaultDate)
                    {
                        return(new CommandResult <UserRecommendation>
                        {
                            isValid = false,
                        });
                    }
                }

                var addInformation = new UserRecommendation()
                {
                    DateCreated = DateTime.Now,
                    ServiceId   = Guid.Parse(idService),
                    UserId      = Guid.Parse(userId)
                };
                await _userRecommendation.Add(addInformation);

                await _userRecommendation.SaveAsync();

                await Logging <ViewUserService> .InformationAsync(ActionCommand.COMMAND_ADD, userId, JsonConvert.SerializeObject(addInformation));

                return(new CommandResult <UserRecommendation>
                {
                    isValid = true,
                    myModel = addInformation
                });
            }
            catch (System.Exception ex)
            {
                return(new CommandResult <UserRecommendation>
                {
                    isValid = false,
                    errorMessage = ex.Message.ToString()
                });
            }
        }
Ejemplo n.º 2
0
 public IActionResult AddRecommendation(UserRecommendation rec)
 {
     if (ModelState.IsValid)
     {
         RecommendationStorage.AddRecommendation(rec);
         ViewData["Added"] = true;
         return(View("UserRecommendations", RecommendationStorage.Recommendations));
     }
     else
     {
         return(View(rec));
     }
 }
 public static PSSecurityAdaptiveApplicationControlsUserRecommendation ConvertToPSType(this UserRecommendation value)
 {
     return(new PSSecurityAdaptiveApplicationControlsUserRecommendation()
     {
         Username = value.Username,
         RecommendationAction = value.RecommendationAction
     });
 }
Ejemplo n.º 4
0
        public static void createTestData(TestContext context)
        {
            #region  Product List and User List Creation - check valid list item for usage

            List <ProductRecommendation> testPR = new List <ProductRecommendation>();
            List <UserRecommendation>    testUR = new List <UserRecommendation>();

            Product product1 = new Product();
            product1.ProductId          = "1";
            product1.ProductName        = "Product1";
            product1.ProductDescription = string.Empty;
            product1.ProductImageurl    = string.Empty;

            Product product2 = new Product();
            product2.ProductId          = "2";
            product2.ProductName        = "Product2";
            product2.ProductDescription = string.Empty;
            product2.ProductImageurl    = string.Empty;

            Product product3 = new Product();
            product3.ProductId          = "3";
            product3.ProductName        = "Product3";
            product3.ProductDescription = string.Empty;
            product3.ProductImageurl    = string.Empty;


            ProductRecommendation pr1 = new ProductRecommendation();
            pr1.Rank    = 1;
            pr1.Product = product1;

            ProductRecommendation pr2 = new ProductRecommendation();
            pr2.Rank    = 2;
            pr2.Product = product2;

            ProductRecommendation pr3 = new ProductRecommendation();
            pr3.Rank    = 3;
            pr3.Product = product3;

            testPR.Add(pr1);
            testPR.Add(pr2);
            testPR.Add(pr3);

            foreach (ProductRecommendation item in testPR)
            {
                string commandText = getCommand(true, item, PARAM_SOURCE_ID, PARAM_PRODUCT_KEY);
                executeCommand(commandText);
            }


            UserRecommendation ur1 = new UserRecommendation();
            ur1.Rank    = 1;
            ur1.Product = product1;


            UserRecommendation ur2 = new UserRecommendation();
            ur2.Rank    = 2;
            ur2.Product = product2;


            UserRecommendation ur3 = new UserRecommendation();
            ur3.Rank    = 3;
            ur3.Product = product3;

            testUR.Add(ur1);
            testUR.Add(ur2);
            testUR.Add(ur3);

            foreach (UserRecommendation item in testUR)
            {
                string commandText = getCommand(true, item, PARAM_SOURCE_ID, PARAM_USER_KEY);
                executeCommand(commandText);
            }

            #endregion  Product List and User List Creation - check valid list item for usage
        }
Ejemplo n.º 5
0
        public void userToProductRecommendationTest()
        {
            bool actual = false;

            Result actualResult;
            Result expectedResult;

            Mock <IWebOperationContext> mockContext = new Mock <IWebOperationContext> {
                DefaultValue = DefaultValue.Mock
            };

            using (new MockedWebOperationContext(mockContext.Object))
            {
                #region Same User List and params from Initialization

                APIPrototypeService target = new APIPrototypeService();
                string tenantId            = PARAM_TENANT_ID;
                string sourceId            = PARAM_SOURCE_ID;
                string userKey             = PARAM_USER_KEY;

                List <UserRecommendation> testUR = new List <UserRecommendation>();

                Product product1 = new Product();
                product1.ProductId          = "1";
                product1.ProductName        = "Product1";
                product1.ProductDescription = string.Empty;
                product1.ProductImageurl    = string.Empty;

                Product product2 = new Product();
                product2.ProductId          = "2";
                product2.ProductName        = "Product2";
                product2.ProductDescription = string.Empty;
                product2.ProductImageurl    = string.Empty;

                Product product3 = new Product();
                product3.ProductId          = "3";
                product3.ProductName        = "Product3";
                product3.ProductDescription = string.Empty;
                product3.ProductImageurl    = string.Empty;

                UserRecommendation ur1 = new UserRecommendation();
                ur1.Rank    = 1;
                ur1.Product = product1;


                UserRecommendation ur2 = new UserRecommendation();
                ur2.Rank    = 2;
                ur2.Product = product2;


                UserRecommendation ur3 = new UserRecommendation();
                ur3.Rank    = 3;
                ur3.Product = product3;

                testUR.Add(ur1);
                testUR.Add(ur2);
                testUR.Add(ur3);

                expectedResult           = new Result();
                expectedResult.tenantId  = long.Parse(tenantId);
                expectedResult.resultSet = testUR;

                #endregion Same User List and params from Initialization

                actualResult = target.userToProductRecommendation(tenantId, sourceId, userKey);
                //Compare values of object expected and actual from service by Value!
                actual = APIPrototype.Utils.ObjectHelper.AreObjectsEqual(actualResult, expectedResult);
            }

            Assert.IsTrue(actual);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns TSQL for given object
        /// </summary>
        /// <param name="isInsert"></param>
        /// <param name="referenceObject"></param>
        /// <param name="sourceSystemId"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string getCommand(bool isInsert, object referenceObject, string sourceSystemId, string key)
        {
            string retVal = string.Empty;

            if (isInsert)
            {
                if (referenceObject.GetType() == typeof(ProductRecommendation))
                {
                    string productInsertQuery = SqlResource.ProductInsertQuery;
                    ProductRecommendation pr  = (ProductRecommendation)referenceObject;

                    productInsertQuery = productInsertQuery.Replace("[[sourcesystemid]]", sourceSystemId);
                    productInsertQuery = productInsertQuery.Replace("[[targetproductid]]", formatSQLInput(key));
                    productInsertQuery = productInsertQuery.Replace("[[productid]]", formatSQLInput(pr.Product.ProductId));
                    productInsertQuery = productInsertQuery.Replace("[[productname]]", formatSQLInput(pr.Product.ProductName));
                    productInsertQuery = productInsertQuery.Replace("[[productdescription]]", formatSQLInput(pr.Product.ProductDescription));
                    productInsertQuery = productInsertQuery.Replace("[[productimageurl]]", formatSQLInput(pr.Product.ProductImageurl));
                    productInsertQuery = productInsertQuery.Replace("[[rank]]", pr.Rank.ToString());

                    retVal = productInsertQuery;
                }
                else if (referenceObject.GetType() == typeof(UserRecommendation))
                {
                    string             userInsertQuery = SqlResource.UserInsertQuery;
                    UserRecommendation ur = (UserRecommendation)referenceObject;

                    userInsertQuery = userInsertQuery.Replace("[[sourcesystemid]]", sourceSystemId);
                    userInsertQuery = userInsertQuery.Replace("[[userid]]", formatSQLInput(key));
                    userInsertQuery = userInsertQuery.Replace("[[productid]]", formatSQLInput(ur.Product.ProductId));
                    userInsertQuery = userInsertQuery.Replace("[[productname]]", formatSQLInput(ur.Product.ProductName));
                    userInsertQuery = userInsertQuery.Replace("[[productdescription]]", formatSQLInput(ur.Product.ProductDescription));
                    userInsertQuery = userInsertQuery.Replace("[[productimageurl]]", formatSQLInput(ur.Product.ProductImageurl));
                    userInsertQuery = userInsertQuery.Replace("[[rank]]", ur.Rank.ToString());

                    retVal = userInsertQuery;
                }
                else
                {
                    throw new Exception("Incorrect command option for given object");
                }
            }
            else // delete command is requested
            {
                if (referenceObject.GetType() == typeof(ProductRecommendation))
                {
                    string productDeleteQuery = SqlResource.ProductDeleteQuery;

                    productDeleteQuery = productDeleteQuery.Replace("[[sourcesystemid]]", sourceSystemId);
                    productDeleteQuery = productDeleteQuery.Replace("[[targetproductid]]", formatSQLInput(key));

                    retVal = productDeleteQuery;
                }
                else if (referenceObject.GetType() == typeof(UserRecommendation))
                {
                    string userDeleteQuery = SqlResource.UserDeleteQuery;

                    userDeleteQuery = userDeleteQuery.Replace("[[sourcesystemid]]", sourceSystemId);
                    userDeleteQuery = userDeleteQuery.Replace("[[userid]]", formatSQLInput(key));

                    retVal = userDeleteQuery;
                }
                else
                {
                    throw new Exception("Incorrect command option for given object");
                }
            }

            return(retVal);
        }
Ejemplo n.º 7
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));
            }
        }
Ejemplo n.º 8
0
 public IActionResult Recommendation(UserRecommendation appResponse)
 {
     TempStorage.AddRecommendation(appResponse);
     return(View("Confirmation", appResponse));
 }