Exemplo n.º 1
0
 public void Put(Guid id, UserViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         _userService.UpdateUser(viewModel);
     }
 }
        public ActionResult Delete(UserViewModel model)
        {
            var user = this.Data.Users.All().FirstOrDefault(c => c.UserName == model.UserName);

            if (user == null)
            {
                return HttpNotFound();
            }

            this.Data.Users.Delete(user);
            user.UserName = Guid.NewGuid().ToString();
            this.Data.SaveChanges();

            return RedirectToAction("Index", "AdminUsers");
        }
        public ActionResult Users_Update([DataSourceRequest]DataSourceRequest request, UserViewModel user)
        {
            if (this.ModelState.IsValid)
            {
                var entity = this.UsersService.GetByUserId(user.Id);

                entity.ImageURL = user.ImageURL;
                entity.Name = user.Name;
                entity.UserImageId = user.UserImageId;
                entity.Email = user.Email;
                entity.UserName = user.UserName;

                this.UsersService.Update(entity);
                this.UsersService.SaveChanges();
            }

            var userToDispley = this.UsersService.GetAll()
               .To<UserViewModel>()
               .FirstOrDefault(x => x.Id == user.Id);

            return this.Json(new[] { userToDispley }.ToDataSourceResult(request, this.ModelState));
        }
Exemplo n.º 4
0
        public async Task<ActionResult> Edit(UserViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var userRoles = await this.UserManager.GetRolesAsync(model.Id);

                if (!this.UserManager.IsInRole(model.Id, model.SelectedRole))
                {
                    var addResult = await this.UserManager.AddToRoleAsync(model.Id, model.SelectedRole);

                    var result = await this.UserManager.RemoveFromRolesAsync(model.Id, userRoles.ToArray());

                    if (!result.Succeeded)
                    {
                        //this.ModelState.AddModelError("", result.Errors.First());
                        return this.RedirectToAction("Index", "Home");
                    }
                }

                var user = this.UserManager.FindById(model.Id);
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                this.UserManager.Update(user);

                var teacher = this.users.GetAllTeachers().FirstOrDefault(t => t.User.Id == model.Id);

                if (this.UserManager.IsInRole(model.Id, GlobalConstants.TeacherRoleName))
                {
                    if (teacher == null)
                    {
                        user.Teacher = new Teacher()
                        {
                            CreatedOn = DateTime.Now,
                        };

                        this.UserManager.Update(user);
                    }
                    else
                    {
                        teacher.IsDeleted = false;
                        teacher.ModifiedOn = DateTime.Now;
                        teacher.DeletedOn = null;
                        this.users.EditTeacher(teacher);
                    }
                }
                else
                {
                    if (teacher != null)
                    {
                        teacher.IsDeleted = true;
                        teacher.DeletedOn = DateTime.Now;
                        this.users.EditTeacher(teacher);
                    }
                }

                var student = this.users.GetAllStudents().FirstOrDefault(t => t.User.Id == model.Id);

                if (this.UserManager.IsInRole(model.Id, GlobalConstants.StudentRoleName))
                {
                    if (student == null)
                    {
                        user.Student = new Student()
                        {
                            CreatedOn = DateTime.Now,
                        };

                        this.UserManager.Update(user);
                    }
                    else
                    {
                        student.IsDeleted = false;
                        student.ModifiedOn = DateTime.Now;
                        student.DeletedOn = null;
                        this.users.EditStudent(student);
                    }
                }
                else
                {
                    if (student != null)
                    {
                        student.IsDeleted = true;
                        student.DeletedOn = DateTime.Now;
                        this.users.EditStudent(student);
                    }
                }

                return this.RedirectToAction("Index");
            }

            return this.View(model);
        }
Exemplo n.º 5
0
        // GET: Administration/Administration/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return this.RedirectToAction("Index");
            }

            var user = this.users.GetById(id);
            if (user == null)
            {
                return this.HttpNotFound();
            }

            var allRoles = this.RoleManager.Roles.Select(
               role => new SelectListItem
               {
                   Text = role.Name,
                   Value = role.Name,
                   Selected = false
               });

            UserViewModel userViewModel = new UserViewModel
            {
                Id = user.Id,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                RolesList = this.UserManager.GetRoles(user.Id)
                                            .Select(role => new SelectListItem { Text = role, Value = role, Selected = true })
                                            .Concat(allRoles)
                                            .GroupBy(r => r.Text)
                                            .Select(grp => grp.FirstOrDefault())
                                            .OrderBy(r => r.Text)
                                            .ToList()
            };

            return this.View(userViewModel);
        }
Exemplo n.º 6
0
        private JsonResult EditResultJson(UserViewModel viewModel)
        {
            if (viewModel.CheckName != viewModel.Entity.UserName)
            {
                if (_service.ExistedName(viewModel.Entity.UserName))
                {
                    return Json(new { result = Constants.Duplicate });
                }
            }
            if (viewModel.EmailCurrent != viewModel.Entity.Email)
            {
                if (_service.ExistedEmail(viewModel.Entity.Email))
                {
                    return Json(new { result = Constants.DuplicateEmail });
                }
            }
            var user = _service.GetByKey(viewModel.Entity.Id);
            if (!Convert.ToBase64String(viewModel.Entity.Timestamp).Equals(Convert.ToBase64String(user.Timestamp)))
            {
                return Json(new { result = Constants.DataJustChanged });
            }

            try
            {
                //user.Id = viewModel.Entity.Id;
                user.UserName = viewModel.Entity.UserName;
                user.FirstName = viewModel.Entity.FirstName;
                user.LastName = viewModel.Entity.LastName;
                user.DepartmentId = viewModel.Entity.DepartmentId;
                user.Department = viewModel.Entity.Department;
                user.Telephone = viewModel.Entity.Telephone;
                user.Mobile = viewModel.Entity.Mobile;
                user.Email = viewModel.Entity.Email;
                //user.Enable = viewModel.Entity.Enable;
                user.Password = !string.IsNullOrEmpty(viewModel.Entity.Password) ? UserCommon.CreateHash(viewModel.Entity.Password) : viewModel.PasswordCurrent;
                user.StoreId = viewModel.Entity.StoreId;
                user.Store = viewModel.Entity.Store;
                //user.CreatedBy = viewModel.Entity.CreatedBy;
                //user.Created = viewModel.Entity.Created;
                user.UserR = viewModel.Entity.UserR;
                user.ProjectR = viewModel.Entity.ProjectR;
                user.StoreR = viewModel.Entity.StoreR;
                user.StockR = viewModel.Entity.StockR;
                user.RequisitionR = viewModel.Entity.RequisitionR;
                user.StockOutR = viewModel.Entity.StockOutR;
                user.StockReturnR = viewModel.Entity.StockReturnR;
                user.StockInR = viewModel.Entity.StockInR;
                user.ReActiveStockR = viewModel.Entity.ReActiveStockR;
                user.StockTypeR = viewModel.Entity.StockTypeR;
                user.CategoryR = viewModel.Entity.CategoryR;
                user.PER = viewModel.Entity.PER;
                user.SupplierR = viewModel.Entity.SupplierR;
                user.PriceR = viewModel.Entity.PriceR;
                user.StockServiceR = viewModel.Entity.StockServiceR;
                user.AccountingR = viewModel.Entity.AccountingR;
                user.MaintenanceR = viewModel.Entity.MaintenanceR;
                user.WorkerR = viewModel.Entity.WorkerR;
                user.ShippmentR = viewModel.Entity.ShippmentR;
                user.ReturnSupplierR = viewModel.Entity.ReturnSupplierR;
                //user.Password =
                user.ModifiedBy = viewModel.LoginId;
                user.Modified = DateTime.Now;

                _service.Update(user);
                return Json(new { result = Constants.Success });
            }
            catch (Exception e)
            {
                Log.Error("Update User!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
Exemplo n.º 7
0
        public ActionResult Create()
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var user = _systemService.GetUserAndRole(0, userName);
            if (user == null) return RedirectToAction("Index", "Login");
            if (user.UserR < 2)
            {
                return RedirectToAction("Index", "Home");
            }
            var userItem = new XUser();
            var model = new UserViewModel
            {
                Id = userItem.Id,
                UserName = userItem.UserName,
                FirstName = userItem.FirstName,
                LastName = userItem.LastName,
                DepartmentId = userItem.DepartmentId,
                Department = userItem.Department,
                Telephone = userItem.Telephone,
                Mobile = userItem.Mobile,
                Email = userItem.Email,
                Enable = userItem.Enable,
                Password = userItem.Password,
                StoreId = userItem.StoreId,
                Store = userItem.Store,
                CreatedBy = userItem.CreatedBy,
                Created = userItem.Created,
                UserR = userItem.UserR,
                ProjectR = userItem.ProjectR,
                StoreR = userItem.StoreR,
                StockR = userItem.StockR,
                RequisitionR = userItem.RequisitionR,
                StockOutR = userItem.StockOutR,
                StockReturnR = userItem.StockReturnR,
                StockInR = userItem.StockInR,
                ReActiveStockR = userItem.ReActiveStockR,
                StockTypeR = userItem.StockTypeR,
                CategoryR = userItem.CategoryR,
                PER = userItem.PER,
                SupplierR = userItem.SupplierR,
                PriceR = userItem.PriceR,
                StockServiceR = userItem.StockServiceR,
                AccountingR = userItem.AccountingR,
                MaintenanceR = userItem.MaintenanceR,
                WorkerR = userItem.WorkerR,
                ShippmentR = userItem.ShippmentR,
                ReturnSupplierR = userItem.ReturnSupplierR,
                Timestamp = userItem.Timestamp,
                UserLogin = user,
                Stores = new SelectList(_systemService.StoreList(), "Id", "Name"),
                Deparments = new SelectList(_systemService.GetLookUp(Constants.LuDepartment), Constants.LookUpKey, Constants.LookUpValue),
                Rights = new SelectList(_systemService.GetLookUp(Constants.LuRight), Constants.LookUpKey, Constants.LookUpValue)
            };

            // FUNCTION
            return View(model);
        }
Exemplo n.º 8
0
        private JsonResult CreateResultJson(UserViewModel viewModel)
        {
            if (_service.ExistedName(viewModel.Entity.UserName))
            {
                return Json(new { result = Constants.Duplicate });
            }

            if (_service.ExistedEmail(viewModel.Entity.Email))
            {
                return Json(new { result = Constants.DuplicateEmail });
            }

            try
            {
                viewModel.Entity.Enable = true;
                viewModel.Entity.Password = UserCommon.CreateHash(viewModel.Entity.Password);
                viewModel.Entity.CreatedBy = viewModel.LoginId;
                viewModel.Entity.Created = DateTime.Now;

                _service.Insert(viewModel.Entity);

                return Json(new { result = Constants.Success });
            }
            catch (Exception e)
            {
                Log.Error("Create New User!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
Exemplo n.º 9
0
 public ActionResult LoadUser(int page, int size, int store, string department, string user, string enable)
 {
     var userName = System.Web.HttpContext.Current.User.Identity.Name;
     var totalRecord = _service.ListConditionCount(page, size, store, department, user, enable);
     var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
     var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
     var model = new UserViewModel
     {
         UserLogin = _systemService.GetUserAndRole(0, userName),
         XUserList = _service.ListCondition(page, size, store, department, user, enable),
         TotalRecords = Convert.ToInt32(totalRecord),
         TotalPages = totalPages,
         CurrentPage = page,
         PageSize = size
     };
     return PartialView("_UserPartial", model);
 }
Exemplo n.º 10
0
        public ActionResult Index()
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var user = _systemService.GetUserAndRole(0, userName);
            if (user == null) return RedirectToAction("Index", "Login");
            if (user.UserR == 0) return RedirectToAction("Index", "Home");
            var model = new UserViewModel
            {
                Stores = new SelectList(_systemService.StoreList(), "Id", "Name"),
                Deparments = new SelectList(_systemService.GetLookUp(Constants.LuDepartment), "LookUpValue", "LookUpValue"),
                UserLogin = user
            };

            return View(model);
        }
Exemplo n.º 11
0
 public ActionResult Edit(UserViewModel viewModelBuilder)
 {
     return viewModelBuilder.V3 != true ? Json(new { result = Constants.UnSuccess }) : EditResultJson(viewModelBuilder);
 }