Ejemplo n.º 1
0
        public async Task <IActionResult> PutOffDay(long id, OffDay offDay)
        {
            if (id != offDay.ID)
            {
                return(BadRequest());
            }

            _context.Entry(offDay).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OffDayExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutPersonel(long id, Personel personel)
        {
            if (id != personel.ID)
            {
                return(BadRequest());
            }

            _context.Entry(personel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Content,SecretCode")] Question question)
        {
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(question));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Content")] Answer answer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(answer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(answer));
        }
Ejemplo n.º 5
0
        public static async Task InvokeAsync(IServiceScope scope, HRDbContext db)
        {
            if (!db.Warehouses.Any())
            {
                await db.Warehouses.AddRangeAsync(new Warehouse
                {
                    Name    = "NewYorker",
                    Address = "."
                }, new Warehouse
                {
                    Name    = "Celio",
                    Address = "."
                }, new Warehouse
                {
                    Name    = "Emporium",
                    Address = "."
                }, new Warehouse
                {
                    Name    = "Mango",
                    Address = "."
                }
                                                  );

                await db.SaveChangesAsync();
            }

            var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();

            if (!roleManager.Roles.Any())
            {
                string[] roles = { "Admin", "HR", "PayrollSpecialist", "DepartmentHead" };
                foreach (var role in roles)
                {
                    await roleManager.CreateAsync(new IdentityRole
                    {
                        Name = role
                    });
                }
            }



            var configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>();

            if (!db.Users.Any())
            {
                var  userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >();
                User admin       = new User
                {
                    Name     = "Admin",
                    Surname  = "Admin",
                    UserName = "******",
                    Email    = "*****@*****.**",
                };
                var adminCreateResult = await userManager.CreateAsync(admin, configuration["Admin:Password"]);

                if (adminCreateResult.Succeeded)
                {
                    await userManager.AddToRoleAsync(admin, "Admin");
                }
            }
        }