public async Task <IHttpActionResult> Put(ApplicationPermission permission)
        {
            db.Entry(permission).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(Ok(permission));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutApplicationRole(string id, ApplicationRole applicationRole)
        {
            if (id != applicationRole.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IHttpActionResult> PutApplicationResource(ApplicationResource applicationResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (applicationResource.Id == null)
            {
                return(BadRequest());
            }
            db = Request.GetOwinContext().Get <SecurityDbContext>();
            db.Entry(applicationResource).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplicationResourceExists(applicationResource.Id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(Ok(applicationResource));
        }
Esempio n. 4
0
        public ActionResult Action([Bind(Include = "UserId,UserName,Password,Salt,FirstName,LastName,Email,Phone,Address,SecurityQuestion,SecurityQuestionAnswer,IsActive,LastLogin")] UserRegistration userregistration, int Roles)
        {
            RoleAssignUser roleassignuser = new RoleAssignUser();

            if (ModelState.IsValid)
            {
                db.Entry(userregistration).State = EntityState.Modified;
                roleassignuser.RoleId            = Roles;
                roleassignuser.UserId            = userregistration.UserId;
                db.RoleAssignUser.Add(roleassignuser);
                db.SaveChanges();
                return(RedirectToAction("ApproveList"));
            }
            ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", roleassignuser.RoleId);

            return(View(userregistration));
        }
 public ActionResult Edit([Bind(Include = "Id,Name")] Group group)
 {
     if (ModelState.IsValid)
     {
         db.Entry(group).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(group));
 }
 public ActionResult Edit([Bind(Include = "RoleId,RoleName")] Role role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(role));
 }
Esempio n. 7
0
        public async Task DeleteAsync(string plate)
        {
            SecurityDbContext dbContext     = _securityDbContextFactory.CreateDbContext();
            Truck             truckToDelete = new Truck()
            {
                LicensePlate = plate
            };

            dbContext.Entry(truckToDelete).State = EntityState.Deleted;
            await dbContext.SaveChangesAsync();
        }
Esempio n. 8
0
 public ActionResult Edit([Bind(Include = "RoleName,OriginalRoleName,Description")] EditRoleViewModel model)
 {
     if (ModelState.IsValid)
     {
         var role = _db.Roles.First(r => r.Name == model.OriginalRoleName);
         role.Name             = model.RoleName;
         role.Description      = model.Description;
         _db.Entry(role).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
        public ActionResult PasswordReset(string Email, ResetPassword rp)
        {
            if (ModelState.IsValid)
            {
                List <UserRegistration> appusers = db.User.ToList();
                foreach (var appuser in appusers)
                {
                    if (appuser.Email.Equals(Email))
                    {
                        appuser.Password        = encryptionDecryptionUtil.CreatePasswordHash(rp.NewPassword, appuser.Salt);
                        db.Entry(appuser).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Confirmation"));
                    }
                }

                if (ModelState.IsValid)
                {
                    ModelState.AddModelError("", "Something gonna wrong!");
                }
            }
            return(View(rp));
        }
        public async Task <IHttpActionResult> PutApplicationUser(AppUserViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (viewModel.Id == null)
            {
                return(BadRequest());
            }
            // IdentityResult result = await manager.UpdateAsync(applicationUser);
            db      = Request.GetOwinContext().Get <SecurityDbContext>();
            manager = Request.GetOwinContext().Get <ApplicationUserManager>(); ApplicationUser user = manager.FindByEmail(viewModel.Email);

            user.Id             = viewModel.Id;
            user.Email          = viewModel.Email;
            user.FirstName      = viewModel.FirstName;
            user.LastName       = viewModel.LastName;
            user.IsActive       = true;
            user.EmailConfirmed = true;
            user.PhoneNumber    = viewModel.PhoneNumber;
            user.ShopId         = viewModel.ShopId;
            user.UserName       = viewModel.Email;

            db.Entry(user).State = EntityState.Modified;

            try
            {
                IdentityUserRole entity = db.ApplicationUserRoles.FirstOrDefault(x => x.UserId == user.Id);
                db.ApplicationUserRoles.Remove(entity);
                db.SaveChanges();
                var identityUserRole = db.ApplicationUserRoles.Add(new IdentityUserRole {
                    RoleId = viewModel.RoleId, UserId = user.Id
                });
                int i = await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplicationUserExists(user.Id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(Ok(user));
        }
Esempio n. 11
0
        public ActionResult Edit([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,UserName,FirstName,LastName,EmpresaID")] ApplicationUser editUserViewModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(editUserViewModel).State = EntityState.Modified;
                db.SaveChanges();

                if (Helpers.ApplicationContext.CurrentUser.IsSuperAdmin)
                {
                    return(RedirectToAction("Index", "Account"));
                }
                else
                {
                    return(RedirectToAction("Dashboard", "Dashboards"));
                }
            }

            SetViewBagListData(editUserViewModel.EmpresaID);
            return(View(editUserViewModel));
        }
        public ActionResult Index(Login loginModel, string returnUrl)
        {
            if (loginModel.USERNAME == null || loginModel.PASSWARD == null || loginModel.USERNAME.Trim().Equals("") || loginModel.PASSWARD.Trim().Equals(""))
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            List <UserRegistration> appusers = db.User.ToList();

            foreach (var appuser in appusers)
            {
                if (appuser.UserName.Equals(loginModel.USERNAME) && encryptionDecryptionUtil.VerifyPassword(appuser.Password, loginModel.PASSWARD, appuser.Salt))
                {
                    FormsAuthentication.SetAuthCookie(loginModel.USERNAME, false);

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        RoleAssignUser userpermission = db.RoleAssignUser.SingleOrDefault(u => u.UserId == appuser.UserId);
                        if (userpermission == null)
                        {
                            FormsAuthentication.SignOut();
                            return(RedirectToAction("AccessDenied", "Error", null));
                        }
                        appuser.LastLogin       = DateTime.Now;
                        db.Entry(appuser).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            return(View(loginModel));
        }
        public ActionResult Index(ChangePassword changePassword, string returnUrl)
        {
            if (changePassword.UserName == null || changePassword.CurrentPassword == null || changePassword.NewPassword == null || changePassword.ConfirmPassword == null || changePassword.UserName.Trim().Equals("") || changePassword.CurrentPassword.Trim().Equals("") || changePassword.NewPassword.Trim().Equals("") || changePassword.ConfirmPassword.Trim().Equals(""))
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            List <UserRegistration> appusers = db.User.ToList();

            foreach (var appuser in appusers)
            {
                if (appuser.UserName.Equals(changePassword.UserName) && encryptionDecryptionUtil.VerifyPassword(appuser.Password, changePassword.CurrentPassword, appuser.Salt))
                {
                    appuser.Password        = encryptionDecryptionUtil.CreatePasswordHash(changePassword.NewPassword, appuser.Salt);
                    db.Entry(appuser).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (ModelState.IsValid)
            {
                ModelState.AddModelError("", "Wrong Username or Password");
            }
            return(View(changePassword));
        }
Esempio n. 14
0
 public static void DetachLocal <T>(this SecurityDbContext context, T t)
 {
     context.Entry(t).State = EntityState.Detached;
 }