Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

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

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Role).State = EntityState.Modified;
            Role.NormalizedName         = String.IsNullOrEmpty(Role.Name) ? null : Role.Name.ToUpper();
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoleExists(Role.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(SMCPromotion).State = EntityState.Modified;
            SMCPromotion.UpdatedOn = DateTime.Now;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SMCPromotionExists(SMCPromotion.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Role.NormalizedName = String.IsNullOrEmpty(Role.Name) ? null : Role.Name.ToUpper();
            _context.Role.Add(Role);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.ClientManager.Add(ClientManager);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #6
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Client = await _context.Client.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Example #7
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SMCActivity = await _context.SMCActivity.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Example #8
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ApplicationUser = await _context.ApplicationUser.FindAsync(id);

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

            return(RedirectToPage("./Index"));
        }
Example #9
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (!SMCPromotion.CreatedOn.HasValue)
            {
                SMCPromotion.CreatedOn = DateTime.Now;
            }
            if (!SMCPromotion.UpdatedOn.HasValue)
            {
                SMCPromotion.UpdatedOn = DateTime.Now;
            }
            _context.SMCPromotion.Add(SMCPromotion);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            List <IdentityUserRole <string> > newRoles = new List <IdentityUserRole <string> >();
            List <IdentityUserRole <string> > delRoles = new List <IdentityUserRole <string> >();
            List <IdentityRole> currentRole            = new List <IdentityRole>();
            List <IdentityRole> oldRoles = new List <IdentityRole>();

            foreach (IdentityRole role in _context.Roles.ToList())
            {
                if (await UserManager.IsInRoleAsync(ApplicationUser, role.Name))
                {
                    oldRoles.Add(role);
                }
            }
            foreach (string rid in SelectIds)
            {
                IdentityRole role = await _context.Roles.Where(r => r.Id == rid).FirstOrDefaultAsync();

                if (role != null)
                {
                    currentRole.Add(role);
                }
            }
            foreach (IdentityRole r in currentRole)
            {
                if (!oldRoles.Contains(r))
                {
                    newRoles.Add(new IdentityUserRole <string>()
                    {
                        UserId = this.ApplicationUser.Id,
                        RoleId = r.Id
                    });
                }
            }
            foreach (var r in oldRoles)
            {
                if (!currentRole.Contains(r))
                {
                    var userRole = _context.UserRoles.Where(ur => ur.UserId == this.ApplicationUser.Id && ur.RoleId == r.Id).FirstOrDefault();
                    if (userRole != null)
                    {
                        delRoles.Add(userRole);
                    }
                }
            }
            if (newRoles.Count > 0)
            {
                await _context.UserRoles.AddRangeAsync(newRoles);
            }
            if (delRoles.Count > 0)
            {
                _context.UserRoles.RemoveRange(delRoles);
            }
            await _context.SaveChangesAsync();

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