Пример #1
0
        public async Task <IActionResult> OnGet()
        {
            string token = HttpContext.Session.GetString("token");

            if (token == null)
            {
                return(RedirectToPage("/Index"));
            }

            UserModel = await _webApi.GetUser(token);

            if (UserModel == null || !UserModel.Manager)
            {
                return(RedirectToPage("/Unauthorized"));
            }

            try
            {
                Users = await _webApi.GetUsers(token);
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }

            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(DateTime?date)
        {
            string token = HttpContext.Session.GetString("token");

            if (token == null)
            {
                return(RedirectToPage("/Index"));
            }

            Date = date?.FirstOfMonth() ?? DateTime.Now.FirstOfMonth();
            if (Date > DateTime.Now.FirstOfMonth())
            {
                return(Redirect("/Time"));
            }

            UserModel = await _webApi.GetUser(token);

            if (UserModel == null)
            {
                return(RedirectToPage("/Unauthorized"));
            }

            try
            {
                foreach (TimeDTO time in await _webApi.GetTimes(token, UserModel.Id, Date))
                {
                    switch (time.Category)
                    {
                    case TimeCategory.Maintenance:
                        Maintenance = MaintenanceOriginal = (decimal)time.Amount;
                        break;

                    case TimeCategory.Enhancement:
                        Enhancement = EnhancementOriginal = (decimal)time.Amount;
                        break;

                    case TimeCategory.NewDevelopment:
                        NewDevelopment = NewDevelopmentOriginal = (decimal)time.Amount;
                        break;

                    case TimeCategory.ResearchAndDevelopment:
                        ResearchAndDevelopment = ResearchAndDevelopmentOriginal = (decimal)time.Amount;
                        break;

                    case TimeCategory.Management:
                        Management = ManagementOriginal = (decimal)time.Amount;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }

            return(Page());
        }
        public async Task <IActionResult> OnGet(DateTime?date)
        {
            DateTime now = DateTime.Now.FirstOfMonth();

            string token = HttpContext.Session.GetString("token");

            if (token == null)
            {
                return(RedirectToPage("/Index"));
            }

            Date = date?.FirstOfMonth() ?? now;
            if (Date > now)
            {
                return(Redirect("/Management/Time"));
            }

            UserModel = await _webApi.GetUser(token);

            if (UserModel == null || !UserModel.Manager)
            {
                return(RedirectToPage("/Unauthorized"));
            }

            try
            {
                Users.Clear();
                foreach (UserDTO user in (await _webApi.GetUsers(token)).Where(x => x.Deactivated == null || x.Deactivated > Date))
                {
                    Users.Add(new UserTimeDTO
                    {
                        User  = user,
                        Times = await _webApi.GetTimes(token, user.Id, Date)
                    });
                }
                FillUserTimes();
            }
            catch (Exception ex)
            {
                Message = ex.Message;
            }

            return(Page());
        }
Пример #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            string token = await _webApi.Login(Email, Password);

            if (!String.IsNullOrWhiteSpace(token))
            {
                UserDTO user = await _webApi.GetUser(token);

                HttpContext.Session.SetString("token", token);
                return(RedirectToPage("/Time"));
            }
            Message = "Invalid Login";
            return(Page());
        }