コード例 #1
0
        public IActionResult GetReportUsers(DateTime?dateWith = null, DateTime?dateTo = null)
        {
            try
            {
                string currentEmail = this.User.FindFirst(ClaimTypes.Name).Value;
                string myUserId     = _userHelper.GetUserId(currentEmail);

                if (myUserId == null)
                {
                    return(NotFound("User not found"));
                }

                List <List <string> > reportUsersDTOs = null;
                string title = "";

                if (dateWith != null && dateTo == null)
                {
                    reportUsersDTOs = _reportService.GetReportUsers(dateWith.Value);
                    title           = $"Отчёт по всем пользователям за {dateWith.Value.ToString("dd.MM.yyyy")}";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/users/{dateWith.Value.Date.ToShortDateString()}]:" +
                                           $"[info:create report by all users for {dateWith.Value.Date.ToShortDateString()}]:[user:{myUserId}]");
                }
                else if (dateWith != null && dateTo != null)
                {
                    reportUsersDTOs = _reportService.GetReportUsers(dateWith.Value, dateTo.Value);
                    title           = $"Отчёт по всем пользователям с {dateWith.Value.ToString("dd.MM.yyyy")} \nпо {dateTo.Value.ToString("dd.MM.yyyy")}";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/users/{dateWith.Value.Date.ToShortDateString()}/{dateTo.Value.Date.ToShortDateString()}]:" +
                                           $"[info:create report by all users with {dateWith.Value.Date.ToShortDateString()} to {dateTo.Value.Date.ToShortDateString()}]:[user:{myUserId}]");
                }
                else
                {
                    reportUsersDTOs = _reportService.GetReportUsers();
                    title           = "Отчёт по всем пользователям за всё время";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/users]:[info:create report by all users]:[user:{myUserId}]");
                }

                ReportPDF reportUsers = new ReportPDF(_webHostEnvironment);

                return(File(reportUsers.Report(reportUsersDTOs, title), "application/pdf"));
            }
            catch (ValidationException ex)
            {
                _logger.LogError($"[{DateTime.Now.ToString()}]:[[report/users/{dateWith}/{dateTo}]:[error:{ex.Property}, {ex.Message}]");

                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError($"[{DateTime.Now.ToString()}]:[report/users/{dateWith}/{dateTo}]:[error:{ex}]");

                return(BadRequest());
            }
        }
コード例 #2
0
        public IActionResult GetReportProvider(int?providerId, DateTime?dateWith = null, DateTime?dateTo = null)
        {
            _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Report/GetReportProvider");

            try
            {
                var provider = _providerService.GetProvider(providerId);

                if (provider == null)
                {
                    throw new ValidationException(_sharedLocalizer["ProviderNoFind"], "");
                }

                List <List <string> > reportList;
                string title = "";

                if (dateWith != null && dateTo == null)
                {
                    reportList = _reportService.GetReportProvider(providerId, dateWith.Value);
                    title      = $"{_sharedLocalizer["ReportByProvider"]} ({provider.Name}) {_sharedLocalizer["Per"]} {dateWith.Value.ToString("dd.MM.yyyy")}";
                }
                else if (dateWith != null && dateTo != null)
                {
                    reportList = _reportService.GetReportProvider(providerId, dateWith.Value, dateTo.Value);
                    title      = $"{_sharedLocalizer["ReportByProvider"]} ({provider.Name}) {_sharedLocalizer["With"]} {dateWith.Value.ToString("dd.MM.yyyy")} \n {_sharedLocalizer["By"]} {dateTo.Value.ToString("dd.MM.yyyy")}";
                }
                else
                {
                    reportList = _reportService.GetReportProvider(providerId);
                    title      = $"{_sharedLocalizer["ReportByProvider"]} ({provider.Name}) {_sharedLocalizer["ForAllTime_"]} ";
                }

                ReportPDF reportProvider = new ReportPDF(_webHostEnvironment);

                _logger.LogInformation($"{DateTime.Now.ToString()}: Created report by provider {providerId.ToString()}");

                return(File(reportProvider.Report(reportList, title), "application/pdf"));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
                _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
            }

            return(BadRequest(_sharedLocalizer["BadRequest"]));
        }
コード例 #3
0
        public IActionResult GetReportUser(string userId, DateTime?dateWith = null, DateTime?dateTo = null)
        {
            _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Report/GetReportUser");

            try
            {
                var user = _userManager.Users.Where(p => p.Id == userId).FirstOrDefault();

                if (user == null)
                {
                    throw new ValidationException(_sharedLocalizer["UserNotFound"], "");
                }
                List <List <string> > reportUserDTOs = null;
                string title = "";

                if (dateWith != null && dateTo == null)
                {
                    reportUserDTOs = _reportService.GetReportUser(userId, dateWith.Value);
                    title          = $"{_sharedLocalizer["ReportByUser"]} ({user.Email}) {_sharedLocalizer["Per"]} {dateWith.Value.ToString("dd.MM.yyyy")}";
                }
                else if (dateWith != null && dateTo != null)
                {
                    reportUserDTOs = _reportService.GetReportUser(userId, dateWith.Value, dateTo.Value);
                    title          = $"{_sharedLocalizer["ReportByUser"]} ({user.Email}) {_sharedLocalizer["With"]} {dateWith.Value.ToString("dd.MM.yyyy")} \n {_sharedLocalizer["By_"]} {dateTo.Value.ToString("dd.MM.yyyy")}";
                }
                else
                {
                    reportUserDTOs = _reportService.GetReportUser(userId);
                    title          = $"{_sharedLocalizer["ReportByUser"]} ({user.Id}) {_sharedLocalizer["ForAllTime_"]}";
                }

                ReportPDF reportUser = new ReportPDF(_webHostEnvironment);

                _logger.LogInformation($"{DateTime.Now.ToString()}: Created report by user {userId.ToString()}");

                return(File(reportUser.Report(reportUserDTOs, title), "application/pdf"));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
                _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
            }

            return(BadRequest(_sharedLocalizer["BadRequest"]));
        }
コード例 #4
0
        public IActionResult GetReportProviders(DateTime?dateWith = null, DateTime?dateTo = null)
        {
            _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Report/GetReportProviders");

            try
            {
                List <List <string> > reportProvidersDTOs;
                string title = "";

                if (dateWith != null && dateTo == null)
                {
                    reportProvidersDTOs = _reportService.GetReportProviders(dateWith.Value);
                    title = $"{_sharedLocalizer["ReportByProvidersPer"]} {dateWith.Value.ToString("dd.MM.yyyy")}";
                }
                else if (dateWith != null && dateTo != null)
                {
                    reportProvidersDTOs = _reportService.GetReportProviders(dateWith.Value, dateTo.Value);
                    title = $"{_sharedLocalizer["ReportByProvidersWith"]} {dateWith.Value.ToString("dd.MM.yyyy")} \n {_sharedLocalizer["By_"]} {dateTo.Value.ToString("dd.MM.yyyy")}";
                }
                else
                {
                    reportProvidersDTOs = _reportService.GetReportProviders();
                    title = _sharedLocalizer["ReportByProviderForAllTime"];
                }

                ReportPDF reportProviders = new ReportPDF(_webHostEnvironment);

                _logger.LogInformation($"{DateTime.Now.ToString()}: Created report by providers");

                return(File(reportProviders.Report(reportProvidersDTOs, title), "application/pdf"));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
                _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
            }

            return(BadRequest(_sharedLocalizer["BadRequest"]));
        }
コード例 #5
0
        public IActionResult GetReportProvider(int providerId, DateTime?dateWith = null, DateTime?dateTo = null)
        {
            try
            {
                var provider = _providerService.GetProvider(providerId);

                if (provider == null)
                {
                    return(NotFound("Provider not found"));
                }

                string currentEmail = this.User.FindFirst(ClaimTypes.Name).Value;
                string userId       = _userHelper.GetUserId(currentEmail);

                if (userId == null)
                {
                    return(NotFound("User not found"));
                }

                List <List <string> > reportList;
                string title = "";

                if (dateWith != null && dateTo == null)
                {
                    reportList = _reportService.GetReportProvider(providerId, dateWith.Value);
                    title      = $"Отчёт по поставщику ({provider.Name}) за {dateWith.Value.ToString("dd.MM.yyyy")}";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/provider/{providerId}/{dateWith.Value.Date.ToShortDateString()}]:[info:create report by provider {providerId} for {dateWith.Value.Date.ToShortDateString()}]:[user:{userId}]");
                }
                else if (dateWith != null && dateTo != null)
                {
                    reportList = _reportService.GetReportProvider(providerId, dateWith.Value, dateTo.Value);
                    title      = $"Отчёт по поставщику ({provider.Name}) с {dateWith.Value.ToString("dd.MM.yyyy")} \nпо {dateTo.Value.ToString("dd.MM.yyyy")}";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/provider/{providerId}/{dateWith.Value.Date.ToShortDateString()}/{dateTo.Value.Date.ToShortDateString()}]:[info:create report by provider {providerId} with {dateWith.Value.Date.ToShortDateString()} to {dateTo.Value.Date.ToShortDateString()}]:[user:{userId}]");
                }
                else
                {
                    reportList = _reportService.GetReportProvider(providerId);
                    title      = $"Отчёт по поставщику ({provider.Name}) за всё время";

                    _logger.LogInformation($"[{DateTime.Now.ToString()}]:[report/provider/{providerId}]:[info:create report by provider {providerId}]:[user:{userId}]");
                }

                ReportPDF reportProvider = new ReportPDF(_webHostEnvironment);

                return(File(reportProvider.Report(reportList, title), "application/pdf"));
            }
            catch (ValidationException ex)
            {
                _logger.LogError($"[{DateTime.Now.ToString()}]:[report/provider/{providerId}/{dateWith}/{dateTo}]:[error:{ex.Property}, {ex.Message}]");

                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError($"[{DateTime.Now.ToString()}]:[report/provider/{providerId}/{dateWith}/{dateTo}]:[error:{ex}]");


                return(BadRequest());
            }
        }