public async Task UpdateClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync();

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Generete new client with added item id
                var updatedClient = ClientMock.GenerateRandomClient(clientEntity.Id);

                //Update client
                await clientRepository.UpdateClientAsync(updatedClient);

                //Get updated client
                var updatedClientEntity =
                    await context.Clients.Where(x => x.Id == updatedClient.Id).SingleAsync();

                //Assert updated client
                updatedClientEntity.Should().BeEquivalentTo(updatedClient);
            }
        }
        public async Task RemoveClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                //Generate random new client without id
                var client = ClientMock.GenerateRandomClient(0);

                //Add new client
                await clientRepository.AddClientAsync(client);

                //Get new client
                var clientEntity = await context.Clients.Where(x => x.Id == client.Id).SingleAsync();

                //Assert new client
                clientEntity.Should().BeEquivalentTo(client, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Remove client
                await clientRepository.RemoveClientAsync(clientEntity);

                //Try Get Removed client
                var removeClientEntity = await context.Clients.Where(x => x.Id == clientEntity.Id)
                                         .SingleOrDefaultAsync();

                //Assert removed client - it might be null
                removeClientEntity.Should().BeNull();
            }
        }
        public async Task UpdateApiResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var apiResourceRepository = GetApiResourceRepository(context);

                //Generate random new api resource
                var apiResource = ApiResourceMock.GenerateRandomApiResource(0);

                //Add new api resource
                await apiResourceRepository.AddApiResourceAsync(apiResource);

                //Get new api resource
                var newApiResource = await context.ApiResources.Where(x => x.Id == apiResource.Id).SingleOrDefaultAsync();

                //Assert new api resource
                newApiResource.ShouldBeEquivalentTo(apiResource, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(newApiResource).State = EntityState.Detached;

                //Generete new api resource with added item id
                var updatedApiResource = ApiResourceMock.GenerateRandomApiResource(newApiResource.Id);

                //Update api resource
                await apiResourceRepository.UpdateApiResourceAsync(updatedApiResource);

                //Get updated api resource
                var updatedApiResourceEntity = await context.ApiResources.Where(x => x.Id == updatedApiResource.Id).SingleAsync();

                //Assert updated api resource
                updatedApiResource.ShouldBeEquivalentTo(updatedApiResourceEntity);
            }
        }
 public ActionResult Edit([Bind(Include = "ID,Name,Alias,Description,DisplayOrder,Status,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy")] ProductCategory productCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productCategory));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Gender,Expense")] AdminModel adminModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adminModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(adminModel));
 }
Example #6
0
 public ActionResult Edit([Bind(Include = "ID,Name,Alias,CategoryID,Image,MoreImages,Price,PromotionPrice,Description,Content,HotFlag,Quantity,Status,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID = new SelectList(db.ProductCategories, "ID", "Name", product.CategoryID);
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "ID,ParcelID,ProductID,Code,IsSell,IsWarranty,Warranty,ProduceDate,Description,Quantity,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy")] ProductRange productRange)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productRange).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID = new SelectList(db.Products, "ID", "Name", productRange.ProductID);
     return(View(productRange));
 }
Example #8
0
        public async Task <ActionResult> Edit([Bind(Include = "BusinessId,BusinessName,Status")] UserBusiness userBusiness)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userBusiness).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userBusiness));
        }
Example #9
0
        public async Task <ActionResult> Edit([Bind(Include = "CategoryId,CategoryName,OrderNo,Status,UserId")] UserCategory userCategory)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userCategory).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.UserId = new SelectList(db.Administrators, "UserId", "UserName", userCategory.UserId);
            return(View(userCategory));
        }
        public async Task <ActionResult> Edit([Bind(Include = "PermissionId,PermissionName,Description,BusinessId,Status")] UserPermission userPermission)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userPermission).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "UserPermissions", new { id = userPermission.BusinessId }));
            }
            ViewBag.BusinessId = new SelectList(db.Businesseses, "BusinessId", "BusinessName", userPermission.BusinessId);
            return(View(userPermission));
        }
        public async Task <ActionResult> Edit([Bind(Include = "PermissionId,UserId,Description")] UserGrantPermission userGrantPermission)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userGrantPermission).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.UserId       = new SelectList(db.Administrators, "UserId", "UserName", userGrantPermission.UserId);
            ViewBag.PermissionId = new SelectList(db.Permissions, "PermissionId", "PermissionName", userGrantPermission.PermissionId);
            return(View(userGrantPermission));
        }
Example #12
0
        public async Task <bool> SaveOtpAsync(OtpMaster otp)
        {
            bool isSuccess = false;

            // In case from Generating OTP from Automatic redirect to Change Password because of not complex password multiple OTPs can be generated
            // Use this validation to restrict user to generate multiple OTPs
            if (await ValidateUser(otp.UserId, AspectEnums.UserValidationType.LastAttemptDuration))
            {
                _dbContext.Entry(otp).State = EntityState.Added;
                isSuccess = await _dbContext.SaveChangesAsync() > 0;
            }
            return(isSuccess);
        }
Example #13
0
        public async Task <ActionResult> Edit([Bind(Include = "PostId,Title,Brief,Content,Picture,CreateDate,Tags,CategoryId,ViewNo,Status,UserId")] UserPost userPost)
        {
            if (ModelState.IsValid)
            {
                db.Entry(userPost).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.UserId     = new SelectList(db.Administrators, "UserId", "UserName", userPost.UserId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", userPost.CategoryId);
            return(View(userPost));
        }
 private void UpdateLoginDateTime(string email)
 {
     try
     {
         var u = _d.Admin.SingleOrDefault(m => m.Email.Equals(email));
         if (u != null)
         {
             var id = u.Id;
             var a  = _d.Admin.Find(id);
             _d.Entry(a).State = EntityState.Modified;
         }
         _d.SaveChanges();
     }
     catch (Exception e)
     {
         Response.Write(e);
     }
 }
Example #15
0
        public async Task UpdateApiResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IApiResourceRepository apiResourceRepository = new ApiResourceRepository(context);
                IClientRepository      clientRepository      = new ClientRepository(context);

                var localizerApiResourceMock = new Mock <IApiResourceServiceResources>();
                var localizerApiResource     = localizerApiResourceMock.Object;

                var localizerClientResourceMock = new Mock <IClientServiceResources>();
                var localizerClientResource     = localizerClientResourceMock.Object;

                IClientService      clientService      = new ClientService(clientRepository, localizerClientResource);
                IApiResourceService apiResourceService = new ApiResourceService(apiResourceRepository, localizerApiResource, clientService);

                //Generate random new api resource
                var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0);

                await apiResourceService.AddApiResourceAsync(apiResourceDto);

                //Get new api resource
                var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync();

                var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id);

                //Assert new api resource
                apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(apiResource).State = EntityState.Detached;

                //Generete new api resuorce with added item id
                var updatedApiResource = ApiResourceDtoMock.GenerateRandomApiResource(apiResource.Id);

                //Update api resource
                await apiResourceService.UpdateApiResourceAsync(updatedApiResource);

                var updatedApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id);

                //Assert updated api resuorce
                updatedApiResource.ShouldBeEquivalentTo(updatedApiResourceDto, options => options.Excluding(o => o.Id));
            }
        }
Example #16
0
        public async Task UpdateClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var clientRepository = GetClientRepository(context);

                var localizerMock = new Mock <IClientServiceResources>();
                var localizer     = localizerMock.Object;

                var clientService = GetClientService(clientRepository, localizer);

                //Generate random new client without id
                var client = ClientDtoMock.GenerateRandomClient(0);

                //Add new client
                await clientService.AddClientAsync(client);

                //Get new client
                var clientEntity =
                    await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync();

                var clientDto = await clientService.GetClientAsync(clientEntity.Id);

                //Assert new client
                client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Generete new client with added item id
                var updatedClient = ClientDtoMock.GenerateRandomClient(clientDto.Id);

                //Update client
                await clientService.UpdateClientAsync(updatedClient);

                //Get updated client
                var updatedClientEntity = await context.Clients.Where(x => x.Id == updatedClient.Id).SingleAsync();

                var updatedClientDto = await clientService.GetClientAsync(updatedClientEntity.Id);

                //Assert updated client
                updatedClient.ShouldBeEquivalentTo(updatedClientDto, options => options.Excluding(o => o.Id));
            }
        }
Example #17
0
        public async Task UpdateRoleAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var testUserManager = GetTestUserManager(context);
                var testRoleManager = GetTestRoleManager(context);

                var mapper = GetMapper();

                var identityRepository        = GetIdentityRepository(context, testUserManager, testRoleManager, mapper);
                var localizerIdentityResource = new IdentityServiceResources();
                var identityService           = GetIdentityService(identityRepository, localizerIdentityResource, mapper);

                //Generate random new role
                var roleDto = IdentityDtoMock <int> .GenerateRandomRole(0);

                await identityService.CreateRoleAsync(roleDto);

                //Get new role
                var role = await context.Roles.Where(x => x.Name == roleDto.Name).SingleOrDefaultAsync();

                roleDto.Id = role.Id;

                var newRoleDto = await identityService.GetRoleAsync(roleDto.Id.ToString());

                //Assert new role
                roleDto.ShouldBeEquivalentTo(newRoleDto);

                //Detached the added item
                context.Entry(role).State = EntityState.Detached;

                //Generete new role with added item id
                var roleDtoForUpdate = IdentityDtoMock <int> .GenerateRandomRole(role.Id);

                //Update role
                await identityService.UpdateRoleAsync(roleDtoForUpdate);

                var updatedRole = await identityService.GetRoleAsync(roleDtoForUpdate.Id.ToString());

                //Assert updated role
                roleDtoForUpdate.ShouldBeEquivalentTo(updatedRole);
            }
        }
Example #18
0
        public async Task <IActionResult> Edit([FromForm] UpdateAdminModel user)
        {
            var edited = await _context.Users.FindAsync(user.Id).ConfigureAwait(false);

            edited.UserName              = user.UserName;
            edited.Email                 = user.Email;
            edited.PhoneNumber           = user.PhoneNumber;
            edited.Banned                = user.Banned;
            _context.Entry(edited).State = EntityState.Modified;
            if (user.Banned)
            {
                var userClaims = await _context.UserClaims.Where(claim => claim.UserId == user.Id).ToListAsync().ConfigureAwait(false);

                _context.UserClaims.RemoveRange(userClaims);
            }
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(Redirect(nameof(Index)));
        }
Example #19
0
        public async Task UpdateUserAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var testUserManager = GetTestUserManager(context);
                var testRoleManager = GetTestRoleManager(context);

                IIdentityRepository identityRepository = new IdentityRepository(context, testUserManager, testRoleManager);
                var localizerIdentityResource          = new IdentityServiceResources();

                IIdentityService identityService = new IdentityService(identityRepository, localizerIdentityResource);

                //Generate random new user
                var userDto = IdentityDtoMock.GenerateRandomUser(Guid.NewGuid());

                await identityService.CreateUserAsync(userDto);

                //Get new user
                var user = await context.Users.Where(x => x.UserName == userDto.UserName).SingleOrDefaultAsync();

                userDto.Id = user.Id;

                var newUserDto = await identityService.GetUserAsync(userDto);

                //Assert new user
                userDto.Should().BeEquivalentTo(newUserDto);

                //Detached the added item
                context.Entry(user).State = EntityState.Detached;

                //Generete new user with added item id
                var userDtoForUpdate = IdentityDtoMock.GenerateRandomUser(user.Id);

                //Update user
                await identityService.UpdateUserAsync(userDtoForUpdate);

                var updatedUser = await identityService.GetUserAsync(userDtoForUpdate);

                //Assert updated user
                userDtoForUpdate.Should().BeEquivalentTo(updatedUser);
            }
        }
Example #20
0
        public async Task RemoveClientAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                var localizerMock = new Mock <IClientServiceResources>();
                var localizer     = localizerMock.Object;

                IClientService clientService = new ClientService(clientRepository, localizer);

                //Generate random new client without id
                var client = ClientDtoMock.GenerateRandomClient(0);

                //Add new client
                await clientService.AddClientAsync(client);

                //Get new client
                var clientEntity =
                    await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync();

                var clientDto = await clientService.GetClientAsync(clientEntity.Id);

                //Assert new client
                client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(clientEntity).State = EntityState.Detached;

                //Remove client
                await clientService.RemoveClientAsync(clientDto);

                //Try Get Removed client
                var removeClientEntity = await context.Clients.Where(x => x.Id == clientEntity.Id)
                                         .SingleOrDefaultAsync();

                //Assert removed client - it might be null
                removeClientEntity.Should().BeNull();
            }
        }
Example #21
0
        public async Task UpdateIdentityResourceAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IIdentityResourceRepository identityResourceRepository = new IdentityResourceRepository(context);

                var localizerIdentityResourceMock = new Mock <IIdentityResourceServiceResources>();
                var localizerIdentityResource     = localizerIdentityResourceMock.Object;

                IIdentityResourceService identityResourceService = new IdentityResourceService(identityResourceRepository, localizerIdentityResource);

                //Generate random new identity resource
                var identityResourceDto = IdentityResourceDtoMock.GenerateRandomIdentityResource(0);

                await identityResourceService.AddIdentityResourceAsync(identityResourceDto);

                //Get new identity resource
                var identityResource = await context.IdentityResources.Where(x => x.Name == identityResourceDto.Name).SingleOrDefaultAsync();

                var newIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id);

                //Assert new identity resource
                identityResourceDto.ShouldBeEquivalentTo(newIdentityResourceDto, options => options.Excluding(o => o.Id));

                //Detached the added item
                context.Entry(identityResource).State = EntityState.Detached;

                //Generete new identity resuorce with added item id
                var updatedIdentityResource = IdentityResourceDtoMock.GenerateRandomIdentityResource(identityResource.Id);

                //Update identity resuorce
                await identityResourceService.UpdateIdentityResourceAsync(updatedIdentityResource);

                var updatedIdentityResourceDto = await identityResourceService.GetIdentityResourceAsync(identityResource.Id);

                //Assert updated identity resuorce
                updatedIdentityResource.ShouldBeEquivalentTo(updatedIdentityResourceDto, options => options.Excluding(o => o.Id));
            }
        }
Example #22
0
        public async Task <ActionResult> Edit([Bind(Include = "UserId,UserName,Password,FullName,Email,Avatar,IsAdmin,Allowed,CreatedDate")] UserAdministrator userAdministrator)
        {
            if (pic != userAdministrator.Avatar)
            {
                userAdministrator.Avatar = pic;
            }

            if (pass != userAdministrator.Password)
            {
                string passMD5 = Common.Encryptor.MD5Hash(userAdministrator.UserName + userAdministrator.Password);

                userAdministrator.Password = passMD5;
            }

            if (ModelState.IsValid)
            {
                db.Entry(userAdministrator).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userAdministrator));
        }
Example #23
0
 public async Task UpdateAsync(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     await _dbContext.SaveChangesAsync();
 }
Example #24
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
        public async Task UpdateApiScopeAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                var apiResourceRepository = GetApiResourceRepository(context);
                var clientRepository      = GetClientRepository(context);

                var localizerApiResourceMock = new Mock <IApiResourceServiceResources>();
                var localizerApiResource     = localizerApiResourceMock.Object;

                var localizerClientResourceMock = new Mock <IClientServiceResources>();
                var localizerClientResource     = localizerClientResourceMock.Object;

                var clientService      = GetClientService(clientRepository, localizerClientResource);
                var apiResourceService = GetApiResourceService(apiResourceRepository, localizerApiResource, clientService);

                //Generate random new api resource
                var apiResourceDto = ApiResourceDtoMock.GenerateRandomApiResource(0);

                await apiResourceService.AddApiResourceAsync(apiResourceDto);

                //Get new api resource
                var apiResource = await context.ApiResources.Where(x => x.Name == apiResourceDto.Name).SingleOrDefaultAsync();

                var newApiResourceDto = await apiResourceService.GetApiResourceAsync(apiResource.Id);

                //Assert new api resource
                apiResourceDto.ShouldBeEquivalentTo(newApiResourceDto, options => options.Excluding(o => o.Id));

                //Generate random new api scope
                var apiScopeDtoMock = ApiResourceDtoMock.GenerateRandomApiScope(0, newApiResourceDto.Id);

                //Add new api scope
                await apiResourceService.AddApiScopeAsync(apiScopeDtoMock);

                //Get inserted api scope
                var apiScope = await context.ApiScopes.Where(x => x.Name == apiScopeDtoMock.Name && x.ApiResource.Id == newApiResourceDto.Id)
                               .SingleOrDefaultAsync();

                //Map entity to model
                var apiScopesDto = apiScope.ToModel();

                //Get new api scope
                var newApiScope = await apiResourceService.GetApiScopeAsync(apiScopesDto.ApiResourceId, apiScopesDto.ApiScopeId);

                //Assert
                newApiScope.ShouldBeEquivalentTo(apiScopesDto, o => o.Excluding(x => x.ResourceName));

                //Detached the added item
                context.Entry(apiScope).State = EntityState.Detached;

                //Update api scope
                var updatedApiScope = ApiResourceDtoMock.GenerateRandomApiScope(apiScopesDto.ApiScopeId, apiScopesDto.ApiResourceId);

                await apiResourceService.UpdateApiScopeAsync(updatedApiScope);

                var updatedApiScopeDto = await apiResourceService.GetApiScopeAsync(apiScopesDto.ApiResourceId, apiScopesDto.ApiScopeId);

                //Assert updated api scope
                updatedApiScope.ShouldBeEquivalentTo(updatedApiScopeDto, o => o.Excluding(x => x.ResourceName));
            }
        }
Example #26
0
 public IActionResult EditMarketing(Promotion promotion)
 {
     _db.Entry(promotion).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Marketing"));
 }