예제 #1
0
        public async Task <IActionResult> PutStaffWorkingHour(int id, StaffWorkingHour staffWorkingHour)
        {
            if (id != staffWorkingHour.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutMessage(int id, Message message)
        {
            if (id != message.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCity(int id, City city)
        {
            if (id != city.Id)
            {
                return(BadRequest());
            }

            //var sourceCity = _context.Cities.Where(i => i.Id == city.Id).FirstOrDefault();
            //if (sourceCity == null) return BadRequest();
            //sourceCity.Name = city.Name;
            //sourceCity.Lat = city.Lat;
            //sourceCity.Lon = city.Lon;

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

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

            return(NoContent());
        }
예제 #4
0
 public async Task CreateAsync(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     entities.Add(entity);
     await _dbContext.SaveChangesAsync();
 }
예제 #5
0
        public async void GetLocation()
        {
            #region Arrange
            // todo: define the required assets
            var storeOptions = Options.Create(new OperationalStoreOptions());
            var options      = new DbContextOptionsBuilder <AmsApiDbContext>()
                               .UseInMemoryDatabase(databaseName: "AmsContext")
                               .Options;
            using (var context = new AmsApiDbContext(options, storeOptions))
            {
                context.Add(new Location()
                {
                    Id           = 1,
                    Active       = true,
                    Address      = "Ab",
                    Address1     = "Ab",
                    Cancelation  = true,
                    City         = "Test city",
                    Confirmation = true,
                    ContactEmail = "*****@*****.**",
                    ContactName  = "Contact NAme",
                    Country      = "CountryName",
                    Description  = "Locatin Description",
                    NoShowUp     = true,
                    Phone        = "12345678901",
                    Reminder     = true,
                    Rescheduling = true,
                    State        = "State testing",
                    ThankYou     = true,
                    ZipCode      = "12345"
                });

                await context.SaveChangesAsync();
            }
            Location location_existing    = null;
            Location location_notExisting = null;

            #endregion


            #region Act
            // todo: invoke the test

            using (var context = new AmsApiDbContext(options, storeOptions))
            {
                var controller = new LocationsForTestController(context);
                location_existing    = (await controller.GetLocation(1)).Value;
                location_notExisting = (await controller.GetLocation(2)).Value;
            }

            #endregion
            #region Assert
            // todo: verify that conditions are met.

            Assert.True(location_existing != null && location_notExisting == null);

            #endregion
        }
        public async Task <ActionResult> CreateDefaultUsers()
        {
            // setup the default role names
            string role_RegisteredUser     = "******";
            string role_RegisteredEmployee = "RegisteredEmployee";
            string role_Administrator      = "Administrator";

            // create the default roles (if they doesn't exist yet)
            if (await _roleManager.FindByNameAsync(role_RegisteredUser) ==
                null)
            {
                await _roleManager.CreateAsync(new
                                               IdentityRole(role_RegisteredUser));
            }
            if (await _roleManager.FindByNameAsync(role_RegisteredEmployee) ==
                null)
            {
                await _roleManager.CreateAsync(new
                                               IdentityRole(role_RegisteredEmployee));
            }
            if (await _roleManager.FindByNameAsync(role_Administrator) ==
                null)
            {
                await _roleManager.CreateAsync(new
                                               IdentityRole(role_Administrator));
            }
            // create a list to track the newly added users

            var addedUserList = new List <ApplicationUser>();
            // check if the admin user already exist
            var email_Admin = "*****@*****.**";

            if (await _userManager.FindByNameAsync(email_Admin) == null)
            {
                // create a new admin ApplicationUser account
                var user_Admin = new ApplicationUser()
                {
                    SecurityStamp = Guid.NewGuid().ToString(),
                    UserName      = email_Admin,
                    Email         = email_Admin,
                };
                // insert the admin user into the DB
                await _userManager.CreateAsync(user_Admin, "MySecr3t$");

                // assign the "RegisteredUser" and "Administrator" roles
                await _userManager.AddToRoleAsync(user_Admin,
                                                  role_RegisteredUser);

                await _userManager.AddToRoleAsync(user_Admin,
                                                  role_Administrator);

                // confirm the e-mail and remove lockout
                user_Admin.EmailConfirmed = true;
                user_Admin.LockoutEnabled = false;
                // add the admin user to the added users list
                addedUserList.Add(user_Admin);
            }
            // check if the standard user already exist
            var email_User = "******";

            if (await _userManager.FindByNameAsync(email_User) == null)
            {
                // create a new standard ApplicationUser account
                var user_User = new ApplicationUser()
                {
                    SecurityStamp = Guid.NewGuid().ToString(),
                    UserName      = email_User,
                    Email         = email_User
                };
                // insert the standard user into the DB
                await _userManager.CreateAsync(user_User, "MySecr3t$");

                // assign the "RegisteredUser" role
                await _userManager.AddToRoleAsync(user_User,
                                                  role_RegisteredUser);

                // confirm the e-mail and remove lockout
                user_User.EmailConfirmed = true;
                user_User.LockoutEnabled = false;
                // add the standard user to the added users list
                addedUserList.Add(user_User);
            }
            // check if the standard user already exist
            var email_Employee = "*****@*****.**";

            if (await _userManager.FindByNameAsync(email_Employee) == null)
            {
                // create a new standard ApplicationUser account
                var user_Employee = new ApplicationUser()
                {
                    SecurityStamp = Guid.NewGuid().ToString(),
                    UserName      = email_Employee,
                    Email         = email_Employee
                };
                // insert the standard user into the DB
                await _userManager.CreateAsync(user_Employee, "MySecr3t$");

                // assign the "RegisteredUser" role
                await _userManager.AddToRoleAsync(user_Employee,
                                                  role_RegisteredEmployee);

                // confirm the e-mail and remove lockout
                user_Employee.EmailConfirmed = true;
                user_Employee.LockoutEnabled = false;
                // add the standard user to the added users list
                addedUserList.Add(user_Employee);
            }
            // if we added at least one user, persist the changes into the DB
            if (addedUserList.Count > 0)
            {
                await _context.SaveChangesAsync();
            }
            return(new JsonResult(new
            {
                Count = addedUserList.Count,
                Users = addedUserList
            }));
        }