Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var employeeToUpdate = await _context.Employees.FindAsync(id);

            if (await TryUpdateModelAsync <Employee>(
                    employeeToUpdate,
                    "employee", // Prefix for form value.
                    e => e.FirstName, e => e.LastName, e => e.RegionId,
                    e => e.DateOfBirth, e => e.Address, e => e.PhoneNumber,
                    e => e.RoleId, e => e.DepartmentId, e => e.PositionId,
                    e => e.Commission, e => e.Salary, e => e.MyManagerId,
                    e => e.UserId))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            // Select DepartmentID if TryUpdateModelAsync fails.
            PopulateRegionDropDownList(_context, employeeToUpdate.Region);
            PopulateRoleDropDownList(_context, employeeToUpdate.Role);
            PopulatePositionDropDownList(_context);
            PopulateRoleDropDownList(_context);
            PopulateManagerDropDownList(_context, Employee.MyManagerId);
            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyReview = new Review();

            var empId = Convert.ToInt32(
                User.Claims
                .Where(c => c.Type == ClaimTypes.PrimarySid)
                .Select(c => c.Value)
                .First()
                );

            if (await TryUpdateModelAsync <Review>(
                    emptyReview,
                    "review", // Prefix for form value.
                    e => e.Comment, e => e.ReviewedEmployeeId))
            {
                emptyReview.ReviewerEmployeeId = empId;
                _context.Reviews.Add(emptyReview);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateReviewedEmployeeDropDownList(_context);
            PopulateReviewingEmployeeDropDownList(_context);
            return(Page());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Region).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RegionExists(Region.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            UserId = Convert.ToInt32(User.Claims
                                     .Where(c => c.Type == ClaimTypes.PrimarySid)
                                     .Select(c => c.Value)
                                     .First());

            var emptyLeave = new Leave();

            if (!ModelState.IsValid)
            {
                PopulateEmployeeDropDownList(_context);
                return(Page());
            }

            Leave.Approved = false;
            if (await TryUpdateModelAsync <Leave>(emptyLeave, "leave",
                                                  l => l.Approved, l => l.StartTime, l => l.EndTime, l => l.EmployeeId))
            {
                _context.Leaves.Add(emptyLeave);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Calendar", new { id = UserId }));
            }

            PopulateEmployeeDropDownList(_context, emptyLeave.Employee);

            return(Page());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Regions.Add(Region);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Employee = await _context.Employees.FindAsync(id);

            if (Employee != null)
            {
                _context.Employees.Remove(Employee);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Leave = await _context.Leaves.FindAsync(id);

            if (Leave != null)
            {
                _context.Leaves.Remove(Leave);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./AwaitingApproval"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                PopulateRegionDropDownList(_context);
                PopulateRoleDropDownList(_context);
                PopulatePositionDropDownList(_context);
                PopulateDepartmentDropDownList(_context);
                return(Page());
            }

            var emptyEmployee = new Employee();

            NewUser newUser = await CreateUser(UserName, Password);

            if (await TryUpdateModelAsync <Employee>(
                    emptyEmployee,
                    "employee", // Prefix for form value.
                    e => e.FirstName, e => e.LastName, e => e.RegionId,
                    e => e.DateOfBirth, e => e.Address, e => e.PhoneNumber,
                    e => e.RoleId, e => e.DepartmentId, e => e.PositionId,
                    e => e.Commission, e => e.Salary))
            {
                emptyEmployee.UserId = newUser.Id;
                _context.Employees.Add(emptyEmployee);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            PopulateRegionDropDownList(_context, emptyEmployee.Region);
            PopulateRoleDropDownList(_context, emptyEmployee.Role);
            PopulatePositionDropDownList(_context);
            PopulateDepartmentDropDownList(_context);
            return(Page());
        }