public ActionResult DisplayUserStatistic()
        {
            try
            {
                string identityKey = User.Identity.GetUserId();
                int    userId      = _userAccountService.ConvertGuidInStringIdToIntId(identityKey);

                decimal totalSpentMoney       = _userStatisticService.GetTotalSpentMoney(userId);
                int     totalBoughtSongAmount = _userStatisticService.GetTotalNumberOfSongs(userId);

                var userStatisticViewModel = new UserStatisticViewModel(totalBoughtSongAmount, totalSpentMoney);

                return(View(userStatisticViewModel));
            }
            catch (ArgumentException exception)
            {
                var innerExcept = exception.InnerException != null ? exception.InnerException.Message : " ";
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, $"{innerExcept} and {exception.Message}"));
            }
            catch (Exception exception)
            {
                var innerExcept = exception.InnerException != null ? exception.InnerException.Message : " ";
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, $"{innerExcept} and {exception.Message}"));
            }
        }
Ejemplo n.º 2
0
        public void DisplayUserStatisticTestByException()
        {
            //Arrange
            UserStatisticViewModel userStatisticViewModel = new UserStatisticViewModel(1, 2);

            mockUserAccountService.Setup(x => x.ConvertGuidInStringIdToIntId(null)).Throws(new Exception("error"));

            mockUserStatisticService.Setup(x => x.GetTotalNumberOfSongs(DEFAULT_ENTITY_ID)).Returns(1);
            mockUserStatisticService.Setup(x => x.GetTotalSpentMoney(DEFAULT_ENTITY_ID)).Returns(2);

            var             userStatisticController = new UserStatisticController(mockUserStatisticService.Object, mockUserAccountService.Object);
            var             userMock = new Mock <IPrincipal>();
            GenericIdentity identity = new GenericIdentity("a");

            userMock.Setup(p => p.Identity).Returns(identity);

            var contextMock = new Mock <HttpContextBase>();

            contextMock.SetupGet(ctx => ctx.User)
            .Returns(userMock.Object);

            var controllerContextMock = new Mock <ControllerContext>();

            controllerContextMock.SetupGet(con => con.HttpContext)
            .Returns(contextMock.Object);

            userStatisticController.ControllerContext = controllerContextMock.Object;

            //Act
            var result = (HttpStatusCodeResult)userStatisticController.DisplayUserStatistic();

            //Assert
            Assert.Equal(500, result.StatusCode);
        }
Ejemplo n.º 3
0
        public IActionResult Index()
        {
            User user = _userService.GetUserById(1);
            UserStatisticViewModel model = new UserStatisticViewModel()
            {
                FirstName       = user.FirstName,
                LastName        = user.LastName,
                AverageFreeTime = user.AverageFreeTime
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public ViewResult GetStatisticPdf(int year, int month)
        {
            UserStatisticDto statistic;
            DateTime         date;
            int day = 1;

            SetUpDate(year, month, ref day, out date, out statistic);

            if (statistic != null)
            {
                var model = new UserStatisticViewModel
                {
                    Year       = year,
                    Month      = date.ToMonthName(),
                    MonthInt   = month,
                    Subscribes = statistic.Subscribes,
                    Sum        = statistic.Sum
                };

                return(View("Report", model));
            }
            return(View("NoData"));
        }