Example #1
0
        public void Update(UpdateUserData model, IValidationErrors errors)
        {
            if (!model.Validate(errors))
            {
                return;
            }

            var user = UnitOfWork.Users.Include(x => x.UserModules).FirstOrDefault(x => x.Id == model.UserId);

            if (user == null)
            {
                throw new Exception("User not found");
            }

            model.MapTo(user);
            foreach (var userModule in user.UserModules)
            {
                var modelUserModule = model.Modules.FirstOrDefault(x => x.Id == userModule.ModuleId);
                if (modelUserModule == null)
                {
                    continue;
                }
                if (modelUserModule.Permission == userModule.Permission)
                {
                    continue;
                }

                modelUserModule.MapTo(userModule);
            }

            UnitOfWork.SaveChanges();
        }