Пример #1
0
        public async Task<IHttpActionResult> Create(UserDto dto)
        {
            if (dto.JobTitle == JobTitle.Valuer || dto.JobTitle == JobTitle.Querying || dto.JobTitle == JobTitle.Manager)
            {
                dto.OutletId = 1;
            }

            string valuerGroup = "10,20,30,40,50";
            if (dto.JobTitle == JobTitle.Purchaser)
            {
                valuerGroup = dto.ValuerGroup;
            }

            User user = new User
            {
                Available = true,
                Cellphone = dto.Cellphone,
                HangOn = false,
                JobTitle = dto.JobTitle,
                OutletId = dto.OutletId,
                UserName = dto.UserName,
                ValuerGroup = valuerGroup
            };

            int outletCode = user.OutletId + 1000;

            string titleCode = "0" + (int)dto.JobTitle;
            titleCode = titleCode.Substring(titleCode.Length - 3, 3);

            string userCode = "{0}{1}{2}".FormatWith(outletCode, titleCode, user.Cellphone.Substring(user.Cellphone.Length - 4, 4));
            user.UserCode = userCode;

            string password = Guid.NewGuid().ToString().Substring(0, 8);

            user.Password = MD5Hash.ComputeMD5Hash(password);

            user = await this.userService.Create(user);

            await this.smsService.SendMessage(user.Cellphone, "登录密码:{0}".FormatWith(password));

            return this.Ok(user.ToDto());
        }
Пример #2
0
        public async Task<IHttpActionResult> Edit([FromUri] int id, UserDto dto)
        {
            User user = await this.userService.Get(id);

            if (user == null)
            {
                return this.BadRequest("无此用户,请确认用户id是否正确");
            }

            user.Cellphone = dto.Cellphone;
            user.JobTitle = dto.JobTitle;
            user.OutletId = dto.OutletId;
            user.UserName = dto.UserName;

            int outletCode = user.OutletId + 1000;

            string titleCode = "0" + dto.JobTitle;
            titleCode = titleCode.Substring(titleCode.Length - 3, 3);

            string userCode = "{0}{1}{2}".FormatWith(outletCode, titleCode, user.Cellphone.Substring(user.Cellphone.Length - 4, 4));
            user.UserCode = userCode;

            return this.Ok((await this.userService.Edit(id, user)).ToDto());
        }