public async Task <ActionResult <HolidayOwner> > PostHolidayOwner(HolidayOwner hOwner)
        {
            _context.HolidayOwners.Add(hOwner);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHolidayOwner), new { id = hOwner.Id }, hOwner));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("VacantionRequestId,FirstName,LastName,Type,StartDate,NoOfDays,Cause")] VacantionRequest vacantionRequest)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vacantionRequest);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacantionRequest));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("VacantionId,VacantionType,VacantionDays,ConsumedDays,DaysLeft")] Vacantion vacantion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vacantion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacantion));
        }
        public async Task <IActionResult> Create([Bind("EmployeeId,FirstName,LastName,HolidayType,NumberOfDays,Date,NumberOfDaysConsumed,NumberOfDaysLeft")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
        public async Task <IActionResult> Create([Bind("Id,City,Year,Score")] Holiday holiday)
        {
            if (ModelState.IsValid)
            {
                _context.Add(holiday);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(holiday));
        }
        public async Task <ActionResult <HolidayHome> > PostHolidayHome(HolidayHome hHome)
        {
            //Checks if the Home owner doesn't exits
            if (!await _context.HolidayOwners.AnyAsync(h => h.Id == hHome.HomeOwnerId))
            {
                return(Content("Holiday Home Owner does not exist"));
            }

            _context.HolidayHomes.Add(hHome);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHolidayHome), new { id = hHome.Id }, hHome));
        }
        public static async Task Seed(HolidayContext context)
        {
            await context.Database.EnsureCreatedAsync();

            var baseDate = new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero);

            DateTimeOffset afterDays(double d)
            => baseDate + TimeSpan.FromDays(d);

            if (context.Employees.Any())
            {
                return;
            }

            await context.Employees.AddRangeAsync(
                new Employee
            {
                Name            = "Standard Employee 1",
                Role            = EmployeeRole.Standard,
                HolidayRequests = new Collection <HolidayRequest>
                {
                    new HolidayRequest
                    {
                        StartDate = afterDays(3),
                        EndDate   = afterDays(4),
                        Status    = HolidayRequestStatus.Pending
                    },
                    new HolidayRequest
                    {
                        StartDate = afterDays(13),
                        EndDate   = afterDays(14),
                        Status    = HolidayRequestStatus.Approved
                    },
                }
            },
                new Employee
            {
                Name            = "Standard Employee 2",
                Role            = EmployeeRole.Standard,
                HolidayRequests = new Collection <HolidayRequest>
                {
                    new HolidayRequest
                    {
                        StartDate = afterDays(43),
                        EndDate   = afterDays(45),
                        Status    = HolidayRequestStatus.Pending
                    },
                    new HolidayRequest
                    {
                        StartDate = afterDays(16),
                        EndDate   = afterDays(21),
                        Status    = HolidayRequestStatus.Refused
                    },
                }
            },
                new Employee
            {
                Name            = "Standard Admin 1",
                Role            = EmployeeRole.Admin,
                HolidayRequests = new Collection <HolidayRequest>
                {
                    new HolidayRequest
                    {
                        StartDate = afterDays(3),
                        EndDate   = afterDays(4),
                        Status    = HolidayRequestStatus.Pending
                    },
                    new HolidayRequest
                    {
                        StartDate = afterDays(13),
                        EndDate   = afterDays(14),
                        Status    = HolidayRequestStatus.Pending
                    },
                }
            },
                new Employee
            {
                Name            = "Standard Employee 1",
                Role            = EmployeeRole.Standard,
                HolidayRequests = new Collection <HolidayRequest>
                {
                    new HolidayRequest
                    {
                        StartDate = afterDays(1),
                        EndDate   = afterDays(30),
                        Status    = HolidayRequestStatus.Refused
                    },
                    new HolidayRequest
                    {
                        StartDate = afterDays(10),
                        EndDate   = afterDays(10.5),
                        Status    = HolidayRequestStatus.Approved
                    },
                }
            });

            await context.SaveChangesAsync();
        }