Example #1
0
        public UserOperatorResult Create(User user, List <Guid> workTypeList)
        {
            if (user == null)
            {
                return(UserOperatorResult.Failed);
            }
            List <CommandParameter> list = new List <CommandParameter>();

            list.Add(new CommandParameter("@account", user.Account));
            if (int.Parse(this._dataBase.ExecuteScalar("SELECT COUNT(Id) FROM [User] WHERE [Account] = @account AND [Removed] = 0", list).ToString()) > 0)
            {
                return(UserOperatorResult.AccountExistent);
            }
            user.Password = IOHelper.GetMD5HashFromString("123");
            this._dataBase.Insert(user);
            list = new List <CommandParameter>();
            list.Add(new CommandParameter("@user", user.Id));
            this._dataBase.ExecuteNonQuery("DELETE [UserWorkType] WHERE [User] = @user", list);
            if (workTypeList != null && workTypeList.Count > 0)
            {
                foreach (Guid current in workTypeList)
                {
                    UserWorkType userWorkType = new UserWorkType();
                    userWorkType.Domain   = user.DomainId;
                    userWorkType.User     = user.Id;
                    userWorkType.WorkType = current;
                    this._dataBase.Insert(userWorkType);
                }
            }
            return(UserOperatorResult.Success);
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("UserWorkTypeId,UserWorkTypeName")] UserWorkType userWorkType)
        {
            if (id != userWorkType.UserWorkTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userWorkType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserWorkTypeExists(userWorkType.UserWorkTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(userWorkType));
        }
Example #3
0
        public UserRegisterResult Register(UserRegisterArgs args)
        {
            UserRegisterResult userRegisterResult = new UserRegisterResult();

            if (args == null)
            {
                userRegisterResult.Result = UserRegisterResultEnum.UserInfoInvalid;
                return(userRegisterResult);
            }
            object lockObj = this._lockObj;

            lock (lockObj)
            {
                List <CommandParameter> list = new List <CommandParameter>();
                list.Add(new CommandParameter("@account", args.Account));
                if (int.Parse(this._dataBase.ExecuteScalar("SELECT Count(Id) FROM [User] WHERE [Account] = @account", list).ToString()) > 0)
                {
                    userRegisterResult.Result = UserRegisterResultEnum.AccountInUse;
                    return(userRegisterResult);
                }
                Domain domain = new Domain();
                UserManager._domainManager.Create(domain);
                Organization organization = new Organization
                {
                    Id     = domain.Id,
                    Domain = domain.Id,
                    Name   = args.DomainName
                };
                UserManager._domainManager.CreateOrganization(organization);
                User user = new User
                {
                    Account        = args.Account,
                    Password       = args.Password,
                    Name           = args.Name,
                    Telphone       = args.Telphone,
                    Email          = args.Email,
                    DomainId       = domain.Id,
                    OrganizationId = organization.Id,
                    Notify         = true
                };
                this._dataBase.Insert(user);
                Dictionary <string, object> dictionary = new Dictionary <string, object> {
                    { "Domain", domain.Id }
                };
                WorkType     workType     = this._dataBase.Select <WorkType>(dictionary)[0];
                UserWorkType userWorkType = new UserWorkType
                {
                    Domain   = domain.Id,
                    User     = user.Id,
                    WorkType = workType.Id
                };
                this._dataBase.Insert(userWorkType);
                userRegisterResult.User   = user;
                userRegisterResult.Domain = domain;
            }
            userRegisterResult.Result = UserRegisterResultEnum.Success;
            return(userRegisterResult);
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("UserWorkTypeId,UserWorkTypeName")] UserWorkType userWorkType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userWorkType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userWorkType));
        }
Example #5
0
 public async Task <UserWorkType> SaveWorkType(UserWorkType obj)
 {
     return(await WithConnection(async c =>
     {
         string sql = $@" INSERT INTO `user_work_type`(
             
             user_id,
             work_type_id
         ) VALUES 
         (
             @UserId,
             @WorkTypeId
             );
             ";
         sql += "SELECT LAST_INSERT_ID() ";
         int newid = await c.QueryFirstOrDefaultAsync <int>(sql, obj);
         obj.Id = newid;
         return obj;
     }));
 }
Example #6
0
        public UserOperatorResult Update(User user, List <Guid> workTypeList)
        {
            if (user == null)
            {
                return(UserOperatorResult.Failed);
            }
            List <CommandParameter> list = new List <CommandParameter>();

            list.Add(new CommandParameter("@id", user.Id));
            list.Add(new CommandParameter("@account", user.Account));
            if (int.Parse(this._dataBase.ExecuteScalar("SELECT COUNT(Id) FROM [User] WHERE [Id] <> @id AND [Account] = @account AND [Removed] = 0", list).ToString()) > 0)
            {
                return(UserOperatorResult.AccountExistent);
            }
            SqlExpression sqlExpression = RelationalMappingUnity.GetSqlExpression(user, new SqlExpressionArgs
            {
                Type          = SqlExpressionType.Update,
                ExcludeFields = "Password"
            });

            this._dataBase.ExcuteSqlExpression(sqlExpression);
            list = new List <CommandParameter>();
            list.Add(new CommandParameter("@user", user.Id));
            this._dataBase.ExecuteNonQuery("DELETE [UserWorkType] WHERE [User] = @user", list);
            if (workTypeList != null && workTypeList.Count > 0)
            {
                foreach (Guid current in workTypeList)
                {
                    UserWorkType userWorkType = new UserWorkType();
                    userWorkType.Domain   = user.DomainId;
                    userWorkType.User     = user.Id;
                    userWorkType.WorkType = current;
                    this._dataBase.Insert(userWorkType);
                }
            }
            return(UserOperatorResult.Success);
        }