예제 #1
0
        public async Task <IActionResult> Edit(int?id, [FromServices] IRepositoryHandler <Employees> repoEmployee)
        {
            if (id != null)
            {
                var task = await repositoryHandler.GetEntryByIDAsync(id.Value, u => u.Reporter.FullName.Equals(User.Identity.Name) ||
                                                                     u.Assignee.FullName.Equals(User.Identity.Name) ||
                                                                     User.IsInRole(EmployeeRole.Admin.ToString()));

                if (task is null)
                {
                    return(new ContentResult {
                        StatusCode = 403, Content = "Forbidden", ContentType = "text/html"
                    });
                }

                var employeesList = await repoEmployee.GetAllEntriesAsync();

                ViewBag.IsAdmin    = User.IsInRole(EmployeeRole.Admin.ToString());
                ViewBag.IsReporter = (await repoEmployee.GetFirstEntityAsync(u => u.FullName.Equals(User.Identity.Name))).Id.Equals(task.ReporterId);

                var model = new TaskEditModelHybrid
                {
                    Task         = task,
                    AssigneeList = new SelectList(employeesList, "Id", "FullName", task.AssigneeId),
                    ReporterList = new SelectList(employeesList, "Id", "FullName", task.ReporterId),
                    PriorityList = TaskEnum.PriorityList((int)task.Priority),
                    StatusList   = TaskEnum.StatusList((int)task.Status),
                };

                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                Employees user = await repositoryHandler.GetFirstEntityAsync(u => u.Email == model.Email && u.Password == model.Password);

                if (user != null)
                {
                    await Authenticate(user);

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("", "Некорректные логин и(или) пароль");
            }
            return(View(model));
        }
        public async Task <IActionResult> Add(StaffAddModelHybrid model, [FromServices] IRepositoryHandler <Role> repoRole)
        {
            if (ModelState.IsValid)
            {
                var employee = mapper.Map <Employees>(model);
                employee.Role = await repoRole.GetFirstEntityAsync(r => r.Name == (EmployeeRole)model.Role);

                repositoryHandler.Create(employee);
            }
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public async Task <IActionResult> Add([FromServices] IRepositoryHandler <Employees> repoEmployee)
        {
            ViewBag.IsAdmin = User.IsInRole(EmployeeRole.Admin.ToString());
            var employeesList = new SelectList(await repoEmployee.GetAllEntriesAsync(), "Id", "FullName");
            var model         = new TaskAddModelHybrid
            {
                ReporterId   = (await repoEmployee.GetFirstEntityAsync(u => u.FullName.Equals(User.Identity.Name))).Id,
                AssigneeList = employeesList,
                ReporterList = employeesList,
                PriorityList = TaskEnum.PriorityList()
            };

            return(View(model));
        }