Esempio n. 1
0
        public JsonResult Register([FromBody] RegisterDto dto)
        {
            var existUser = _context.CanteenUsers.FirstOrDefault(p => p.Name == dto.Username);

            if (existUser != null)
            {
                return(Json(new RequestResult {
                    State = RequestState.Failed, Msg = "用户名已存在"
                }));
            }
            else
            {
                var newUser = new CanteenUser {
                    Name = dto.Username, Password = dto.Password, RealName = dto.RealName, Role = "user"
                };
                _context.CanteenUsers.Add(newUser);
                if (_context.SaveChanges() == 1)
                {
                    return(Json(new RequestResult {
                        State = RequestState.Success
                    }));
                }
                else
                {
                    return(Json(new RequestResult {
                        State = RequestState.Failed, Msg = "保存失败"
                    }));
                }
            }
        }
Esempio n. 2
0
        public bool UnbindDiner(Guid id)
        {
            var existRecord = _context.BindRecords.FirstOrDefault(p => p.ID == id && p.CanteenUserID == GetUserID());

            if (existRecord == null)
            {
                return(false);
            }
            _context.BindRecords.Remove(existRecord);
            if (_context.SaveChanges() == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }