Example #1
0
        public ActionResult GetWatchListSetting(int selectedItem)
        {
            WatchListDTO            watchList       = new WatchListDTO();
            ShipperReturnByIdentity currentIdentity = GetValueFromIdentity();
            var user = SignInManager.UserManager.FindById(currentIdentity.UserId);

            if (user != null)
            {
                watchList.UserEmail = user.Email;
            }

            watchList.RuleList = new List <WatchListRule>()
            {
            };
            ViewBag.Pipeline = GetPipelines(); // pipelineService.GetAllPipelineList(GetCurrentCompanyID(),GetLoggedInUserId());
            switch (selectedItem)
            {
            case 1:
                watchList.DatasetId = Enums.EnercrossDataSets.OACY;
                break;

            case 2:
                watchList.DatasetId = Enums.EnercrossDataSets.UNSC;
                break;

            case 3:
                watchList.DatasetId = Enums.EnercrossDataSets.SWNT;
                break;
            }
            return(PartialView(watchList));
        }
Example #2
0
        public async Task GetAllWatchLists()
        {
            string url = ApiPaths.WATCH_LIST_ALL_PATH;
            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "userId", this.TestWatchListCustom.PartitionKey }
            };

            var response = await this.Consumer.ExecuteRequest(url, queryParams, null, Method.GET);

            Assert.True(response.Status == HttpStatusCode.OK);

            List <WatchListDTO>    parsedResponse = JsonUtils.DeserializeJson <List <WatchListDTO> >(response.ResponseJson);
            List <WatchListEntity> userWatchLists = this.AllWatchListsFromDBCustom.Where(w => w.PartitionKey == this.TestWatchListCustom.PartitionKey).ToList();

            userWatchLists.AddRange(this.AllWatchListsFromDBPredefined);

            foreach (WatchListEntity entity in userWatchLists)
            {
                WatchListDTO parsedMatch = parsedResponse.Where(p => p.Id == entity.Id).FirstOrDefault();
                entity.ShouldBeEquivalentTo(parsedMatch, o => o
                                            .ExcludingMissingMembers()
                                            .Excluding(e => e.AssetIds)
                                            .Excluding(e => e.ReadOnly));

                foreach (string assetId in parsedMatch.AssetIds)
                {
                    entity.AssetIDsList.Should().Contain(assetId);
                }
            }
        }
Example #3
0
        public async Task GetAllWatchListsPredefined()
        {
            string url      = ApiPaths.WATCH_LIST_PREDEFINED_PATH;
            var    response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.GET);

            Assert.True(response.Status == HttpStatusCode.OK);

            List <WatchListDTO> parsedResponse = JsonUtils.DeserializeJson <List <WatchListDTO> >(response.ResponseJson);

            foreach (WatchListEntity entity in this.AllWatchListsFromDBPredefined)
            {
                WatchListDTO parsedMatch = parsedResponse.Where(p => p.Id == entity.Id).FirstOrDefault();
                entity.ShouldBeEquivalentTo(parsedMatch, o => o
                                            .ExcludingMissingMembers()
                                            .Excluding(e => e.AssetIds)
                                            .Excluding(e => e.ReadOnly));

                Assert.True(parsedMatch.ReadOnly);

                entity.AssetIDsList.Should().HaveSameCount(parsedMatch.AssetIds);

                foreach (string assetId in entity.AssetIDsList)
                {
                    parsedMatch.AssetIds.Should().Contain(assetId);
                }
            }
        }
Example #4
0
        public async Task GetSingleWatchListsCustom()
        {
            string url = ApiPaths.WATCH_LIST_CUSTOM_PATH + "/" + this.TestWatchListCustom.Id;
            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "userId", this.TestWatchListCustom.PartitionKey }
            };

            var response = await this.Consumer.ExecuteRequest(url, queryParams, null, Method.GET);

            Assert.True(response.Status == HttpStatusCode.OK);

            WatchListDTO parsedResponse = JsonUtils.DeserializeJson <WatchListDTO>(response.ResponseJson);

            this.TestWatchListCustom.ShouldBeEquivalentTo(parsedResponse, o => o
                                                          .ExcludingMissingMembers()
                                                          .Excluding(e => e.AssetIds)
                                                          .Excluding(e => e.ReadOnly));

            Assert.False(parsedResponse.ReadOnly);

            foreach (string assetId in this.TestWatchListCustom.AssetIDsList)
            {
                parsedResponse.AssetIds.Should().Contain(assetId);
            }
        }
Example #5
0
        public ActionResult Index(int watchListId = 0)
        {
            if (TempData["Msg"] != null)
            {
                ViewBag.Status = TempData["Msg"] + "";
            }
            WatchListDTO watchList = new WatchListDTO();

            if (watchListId != 0)
            {
                ViewBag.EditFlag = watchListId + "";
                RestRequest request = new RestRequest("GetWatchListById/" + watchListId, Method.GET);
                IRestResponse <WatchListDTO> response = client.Execute <WatchListDTO>(request);
                if (response.IsSuccessful)
                {
                    watchList.DatasetId = response.Data.DatasetId;
                }
                watchList.id = watchListId;
            }

            watchList.RuleList = new List <WatchListRule>()
            {
                new WatchListRule()
                {
                }
            };
            return(View(watchList));
        }
Example #6
0
        public ActionResult AddRuleSettings(int datasetId)
        {
            WatchListDTO watchList = new WatchListDTO();

            switch (datasetId)
            {
            case 1:
                watchList.DatasetId = Enums.EnercrossDataSets.OACY;
                break;

            case 2:
                watchList.DatasetId = Enums.EnercrossDataSets.UNSC;
                break;

            case 3:
                watchList.DatasetId = Enums.EnercrossDataSets.SWNT;
                break;
            }
            RestRequest requestForProp = new RestRequest("GetPropertiesByDataSet", Method.GET);

            requestForProp.AddQueryParameter("dataset", watchList.DatasetId.ToString());
            requestForProp.JsonSerializer = NewtonsoftJsonSerializer.Default;
            IRestResponse <List <WatchListProperty> > responseForProp = client.Execute <List <WatchListProperty> >(requestForProp);
            List <WatchListProperty> properties = responseForProp.Data != null ? responseForProp.Data : new List <WatchListProperty>(); //IWatchlistService.GetPropertiesByDataSet(watchList.DatasetId);

            ViewBag.Properties = properties;

            if (properties.Count > 0)
            {
                ViewBag.Operators = properties.FirstOrDefault().Operators;
            }
            else
            {
                ViewBag.Operators = new List <WatchListOperator>();
            }
            List <WatchListRule> newwatchRule = new List <WatchListRule>()
            {
                new WatchListRule()
                {
                }
            };

            watchList.RuleList = newwatchRule;

            // var pipelineList = pipelineService.GetAllPipelineList(GetCurrentCompanyID(),GetLoggedInUserId());
            ViewBag.PipelineId = GetPipelines();

            ViewBag.LocationIdentifier = new List <LocationsDTO>();
            if (watchList.DatasetId == Enums.EnercrossDataSets.OACY)
            {
                return(PartialView("OacyRuleSettings", watchList));
            }
            else
            {
                return(PartialView(watchList));
            }
        }
Example #7
0
        public IHttpActionResult UpdateWatchList([FromBody] WatchListDTO watchListDto)
        {
            bool result = false;

            if (watchListDto != null)
            {
                WatchlistService.UpdateWatchList(watchListDto);
                result = true;
            }
            return(Json(result));
        }
Example #8
0
        public async Task DeletePredefinedWatchList()
        {
            WatchListDTO TestWatchListPredefinedDelete = await CreateTestWatchList();

            string url      = ApiPaths.WATCH_LIST_PREDEFINED_PATH + "/" + TestWatchListPredefinedDelete.Id;
            var    response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.DELETE);

            Assert.True(response.Status == HttpStatusCode.NoContent);

            WatchListEntity entity = await this.WatchListRepository.TryGetAsync("PublicWatchList", TestWatchListPredefinedDelete.Id) as WatchListEntity;

            Assert.Null(entity);
        }
Example #9
0
        public ActionResult Index(WatchListDTO watchlist, string Save)
        {
            var msg = Validation(watchlist);

            if (string.IsNullOrEmpty(msg))
            {
                ShipperReturnByIdentity currentIdentity = GetValueFromIdentity();
                watchlist.UserId = currentIdentity.UserId;
                var url = BaseUrl();

                watchlist.MoreDetailURLinAlert = url;
                if (Save == "Update")
                {
                    // Code for Update

                    RestRequest request = new RestRequest("UpdateWatchList", Method.POST);
                    request.JsonSerializer = NewtonsoftJsonSerializer.Default;
                    request.AddJsonBody(watchlist);
                    IRestResponse <bool> response = client.Execute <bool>(request);
                    return(RedirectToAction("List"));
                }
                else
                {
                    //Code for Save
                    RestRequest request = new RestRequest("SaveWatchList", Method.POST);
                    request.JsonSerializer = NewtonsoftJsonSerializer.Default;
                    request.AddJsonBody(watchlist);
                    IRestResponse <bool> response = client.Execute <bool>(request);
                    bool save = response.Data;
                    if (save != false)
                    {
                        TempData["Msg"] = "Data saved successfully";
                    }
                    else
                    {
                        TempData["Msg"] = "Data saving failed";
                    }
                    return(RedirectToAction("Index", new { watchListId = 0 }));
                }
            }
            else
            {
                TempData["Msg"] = "Action failed." + msg;
                return(RedirectToAction("Index", new { watchListId = 0 }));
            }
        }
Example #10
0
        public async Task DeleteCustomWatchList()
        {
            WatchListDTO TestWatchListCustomDelete = await CreateTestWatchList(TestAccountId);

            string url = ApiPaths.WATCH_LIST_CUSTOM_PATH + "/" + TestWatchListCustomDelete.Id;
            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "userId", this.TestAccountId }
            };

            var response = await this.Consumer.ExecuteRequest(url, queryParams, null, Method.DELETE);

            Assert.True(response.Status == HttpStatusCode.NoContent);

            WatchListEntity entity = await this.WatchListRepository.TryGetAsync(this.TestAccountId, TestWatchListCustomDelete.Id) as WatchListEntity;

            Assert.Null(entity);
        }
Example #11
0
        public async Task <WatchListDTO> CreateTestWatchList(string clientId = null)
        {
            string url = ApiPaths.WATCH_LIST_BASE_PATH;
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            bool readOnlyValue = true;

            if (clientId == null)
            {
                url += "/predefined";
            }
            else
            {
                url += "/custom";
                queryParams.Add("userId", clientId);
                readOnlyValue = false;
            }

            WatchListEntity tempalteEntity = EnumerableUtils.PickRandom(AllWatchListsFromDB);
            WatchListDTO    createDTO      = new WatchListDTO()
            {
                Id       = tempalteEntity.Id,
                Name     = tempalteEntity.Name,
                ReadOnly = tempalteEntity.ReadOnly,
                Order    = tempalteEntity.Order,
                AssetIds = tempalteEntity.AssetIDsList
            };

            createDTO.Id      += Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest;
            createDTO.Name    += Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest;
            createDTO.ReadOnly = readOnlyValue;
            string createParam = JsonUtils.SerializeObject(createDTO);

            var response = await Consumer.ExecuteRequest(url, queryParams, createParam, Method.POST);

            if (response.Status != HttpStatusCode.Created)
            {
                return(null);
            }

            AddOneTimeCleanupAction(async() => await DeleteTestWatchList(createDTO.Id, clientId));

            return(createDTO);
        }
Example #12
0
        public async Task UpdateCustomWatchList()
        {
            string url = ApiPaths.WATCH_LIST_CUSTOM_PATH;

            WatchListDTO TestWatchListCustomUpdate = await CreateTestWatchList(TestAccountId);

            Dictionary <string, string> queryParams = new Dictionary <string, string>
            {
                { "userId", this.TestAccountId }
            };
            WatchListDTO updateWatchList = new WatchListDTO()
            {
                Id       = TestWatchListCustomUpdate.Id,
                Name     = TestWatchListCustomUpdate.Name + Helpers.Random.Next(1000, 9999).ToString() + GlobalConstants.AutoTest,
                Order    = Helpers.Random.Next(1, 100),
                ReadOnly = TestWatchListCustomUpdate.ReadOnly,
                AssetIds = TestWatchListCustomUpdate.AssetIds
            };

            updateWatchList.AssetIds.Add("AutoTest");
            string updateParam = JsonUtils.SerializeObject(updateWatchList);

            var response = await this.Consumer.ExecuteRequest(url, queryParams, updateParam, Method.PUT);

            Assert.True(response.Status == HttpStatusCode.NoContent);

            WatchListEntity entity = await this.WatchListRepository.TryGetAsync(this.TestAccountId, updateWatchList.Id) as WatchListEntity;

            Assert.NotNull(entity);
            entity.ShouldBeEquivalentTo(updateWatchList, o => o
                                        .ExcludingMissingMembers()
                                        .Excluding(e => e.AssetIds)
                                        .Excluding(e => e.ReadOnly));

            entity.AssetIDsList.Should().HaveSameCount(updateWatchList.AssetIds);

            foreach (string assetId in entity.AssetIDsList)
            {
                updateWatchList.AssetIds.Should().Contain(assetId);
            }
        }
Example #13
0
        public async Task CreatePredefinedWatchList()
        {
            WatchListDTO createdDTO = await this.CreateTestWatchList();

            Assert.NotNull(createdDTO);

            WatchListEntity entity = await this.WatchListRepository.TryGetAsync("PublicWatchList", createdDTO.Id) as WatchListEntity;

            Assert.NotNull(entity);
            entity.ShouldBeEquivalentTo(createdDTO, o => o
                                        .ExcludingMissingMembers()
                                        .Excluding(e => e.AssetIds)
                                        .Excluding(e => e.ReadOnly));

            entity.AssetIDsList.Should().HaveSameCount(createdDTO.AssetIds);

            foreach (string assetId in entity.AssetIDsList)
            {
                createdDTO.AssetIds.Should().Contain(assetId);
            }
        }
Example #14
0
        public async Task GetSingleWatchListsPredefined()
        {
            string url      = ApiPaths.WATCH_LIST_PREDEFINED_PATH + "/" + this.TestWatchListPredefined.Id;
            var    response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, null, Method.GET);

            Assert.True(response.Status == HttpStatusCode.OK);

            WatchListDTO parsedResponse = JsonUtils.DeserializeJson <WatchListDTO>(response.ResponseJson);

            this.TestWatchListPredefined.ShouldBeEquivalentTo(parsedResponse, o => o
                                                              .ExcludingMissingMembers()
                                                              .Excluding(e => e.AssetIds)
                                                              .Excluding(e => e.ReadOnly));

            Assert.True(parsedResponse.ReadOnly);

            this.TestWatchListPredefined.AssetIDsList.Should().HaveSameCount(parsedResponse.AssetIds);

            foreach (string assetId in this.TestWatchListPredefined.AssetIDsList)
            {
                parsedResponse.AssetIds.Should().Contain(assetId);
            }
        }
        public async Task <WatchListDTO> UpdateWatchlistItem(string id, WatchListDTO watchListDTO)
        {
            if (watchListDTO == null)
            {
                throw new ArgumentNullException(nameof(watchListDTO));
            }

            try
            {
                WatchList watchlist = await _context.WatchLists
                                      .FirstOrDefaultAsync(w => w.UserId == id && w.MovieId == watchListDTO.MovieId).ConfigureAwait(false);

                watchlist.Status = getStatus(watchListDTO.Status);
                watchlist.Score  = watchListDTO.Score;

                await _context.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (await UserExists(id).ConfigureAwait(false) == false)
                {
                    return(null);
                }
                else
                {
                    throw;
                }
            }
            return(new WatchListDTO()
            {
                UserId = id,
                MovieId = watchListDTO.MovieId,
                Status = watchListDTO.Status,
                Score = watchListDTO.Score
            });
        }
Example #16
0
        public string Validation(WatchListDTO watchlist)
        {
            string msg = string.Empty;

            if (watchlist.DatasetId == 0)
            {
                return("Please, Select DataSet for watchlist.");
            }
            if (string.IsNullOrEmpty(watchlist.ListName) || string.IsNullOrWhiteSpace(watchlist.ListName))
            {
                return("Please, Eneter watchLlist Name.");
            }
            if (watchlist.RuleList == null || watchlist.RuleList.Count == 0)
            {
                return("Please, Select at least one Rule for watchlist.");
            }
            if (watchlist.RuleList.Count > 0)
            {
                foreach (var item in watchlist.RuleList)
                {
                    if (item.PropertyId == 0 && watchlist.DatasetId == EnercrossDataSets.SWNT)
                    {
                        continue;
                    }
                    if (item.PropertyId == 0)
                    {
                        return("Please, select Column for watchlist Rule.");
                    }
                    if (watchlist.DatasetId != EnercrossDataSets.OACY)
                    {
                        if (item.ComparatorsId == 0)
                        {
                            return("Please, select condition for watchlist Rule");
                        }
                    }

                    if (string.IsNullOrEmpty(item.value) || string.IsNullOrWhiteSpace(item.value))
                    {
                        return("Please, enter value for rule of watchlist.");
                    }
                    try {
                        RestRequest requestForProp = new RestRequest("GetPropertyById", Method.GET);
                        requestForProp.AddQueryParameter("propertyId", item.PropertyId.ToString());
                        IRestResponse <WatchListProperty> responseForProp = client.Execute <WatchListProperty>(requestForProp);
                        var prop = responseForProp.Data;
                        if (prop.Datatype == "decimal")
                        {
                            var dec = decimal.Parse(item.value);
                        }
                        if (prop.Datatype == "long")
                        {
                            var lon = long.Parse(item.value);
                        }
                        if (prop.Datatype == "DateTime")
                        {
                            var dat = DateTime.ParseExact(item.value, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        }
                    } catch (Exception ex) {
                        return("Please, Enter Value in Correct Format. Don't use any special character in value.");
                    }
                }
            }
            return(msg);
        }
Example #17
0
        public async Task <ActionResult <WatchListDTO> > UpdateWatchlistItem(string id, WatchListDTO watchListDTO)
        {
            var watchlistResult = await _userRepository.UpdateWatchlistItem(id, watchListDTO).ConfigureAwait(false);

            if (watchlistResult == null)
            {
                return(NotFound());
            }

            return(watchlistResult);
        }