コード例 #1
0
ファイル: UserAddController.cs プロジェクト: 115happy/SD2
        public IHttpActionResult PostUserAdd(UserIntactDto user)
        {
            string msg = "";

            if (user == null)
            {
                msg = "参数错误";
            }
            var userToAdd = Mapper.Map <UserIntactDto, User>(user);

            userToAdd.Password = Encoder.Encode(userToAdd.Password);
            try
            {
                _context.Users.Add(userToAdd);
                _context.SaveChanges();
                msg = "添加成功";
            }
            catch (RetryLimitExceededException)
            {
                msg = "网络故障";
            }
            var str = "{ \"Message\" : \"" + msg + "\" , \"" + "Data\" : \"" + "null" + "\" }";

            return(Ok(str));
        }
コード例 #2
0
        public IHttpActionResult PostUserDelete(UserIntactDto user)
        {
            string msg = "";

            if (user == null)
            {
                msg = "参数错误";
            }
            var userToDelete = _context.Users.Find(user.Id);

            if (userToDelete == null)
            {
                msg = "删除失败,该用户不存在";
            }
            else
            {
                try
                {
                    _context.Users.Remove(userToDelete);
                    _context.SaveChanges();
                    msg = "删除成功";
                }
                catch (RetryLimitExceededException)
                {
                    msg = "网络故障";
                }
            }

            var str = "{ \"Message\" : \"" + msg + "\" , \"" + "Data\" : \"" + "null" + "\" }";

            return(Ok(str));
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: 115happy/SD2
        public ActionResult Index(string Name)
        {
            User          userToUpdate          = _context.Users.Where(u => u.Name == Name).FirstOrDefault();
            UserIntactDto userToUpdateIntactDto = Mapper.Map <User, UserIntactDto>(userToUpdate);

            // Protect the password
            userToUpdateIntactDto.Password = string.Empty;

            return(View(userToUpdateIntactDto));
        }
コード例 #4
0
ファイル: UserModifyController.cs プロジェクト: 115happy/SD2
        public IHttpActionResult PostUserModify(UserIntactDto user)
        {
            string msg = "";

            if (user == null)
            {
                msg = MsgInputErr;
            }

            var userToUpdate = _context.Users.Find(user.Id);

            if (userToUpdate.Password == Encoder.Encode(user.Password))
            {
                msg = MsgExsistingPasswordErr;
            }
            else
            {
                try
                {
                    var tmpPassword = userToUpdate.Password;
                    Mapper.Map(user, userToUpdate);
                    if (user.Password.Trim() == "")
                    {
                        userToUpdate.Password = tmpPassword;
                    }
                    else
                    {
                        userToUpdate.Password = Encoder.Encode(user.Password);
                    }
                    _context.SaveChanges();
                    msg = MsgSuccess;
                }
                catch (RetryLimitExceededException)
                {
                    msg = MsgException;
                }
            }

            //var userToUpdate = _context.Users.Find(user.Id);
            //userToUpdate = Mapper.Map<UserIntactDto, User>(user);
            //userToUpdate.Password = Encoder.Encode(user.Password);
            //userToUpdate.Name = user.Name;
            //userToUpdate.Authority = user.Authority;
            //userToUpdate.IsToRememberMe = user.IsToRememberMe;
            //try
            //{
            //    _context.Entry(userToUpdate).State = EntityState.Modified;
            //    _context.SaveChanges();
            //    msg = "修改成功";
            //}
            //catch (RetryLimitExceededException)
            //{
            //    msg = "网络故障";
            //}
            //var str = string.Format("{\'Message\': \'{0}\', \'Data\':  \'null\'}", msg);
            var str = $"{{'{Message}' : '{msg}', '{Data}' : 'null'}}";

            str = str.Replace('\'', '"');
            //var str = "{ \"Message\" : \"" + msg + "\" , \"" + "Data\" : \"" + "null" + "\" }";
            return(Ok(str));
        }