Esempio n. 1
0
        public Users CreateUser(Users user)
        {
            _context.Add(user);
            _context.SaveChanges();

            return(user);
        }
Esempio n. 2
0
        public StatusCodeResult Post([FromBody] GroceryListItemModel value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var result = _context.GroceryListItems.Add(value);

            _context.SaveChanges();

            return(Ok());
        }
Esempio n. 3
0
        public IActionResult Create(UserViewModel user)
        {
            var userd = _context.Users.Add(new Users()
            {
                Phone    = user.Phone,
                UserName = user.UserName
            });

            _context.SaveChanges();
            return(Redirect("index"));
        }
Esempio n. 4
0
        //[Route("get")]
        public string get()
        {
            db.Config.Add(new Config()
            {
                id = Guid.NewGuid().ToString(), name = Guid.NewGuid().ToString()
            });
            db.SaveChanges();
            var result = db.Config.ToList();

            return(JsonConvert.SerializeObject(result));
        }
Esempio n. 5
0
 public IHttpActionResult GameOver([FromBody] EndAction_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.Roomid < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var room      = db.Rooms.Where(t => t.RoomId == RequestMod.Roomid & t.IsQuit == false).FirstOrDefault();
             var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.Roomid);
             if (room == null || roomroles == null)
             {
                 throw new ArgumentException("房间不存在");
             }
             db.RoomRoles.RemoveRange(roomroles);
             int i = db.SaveChanges();
             GoInRoom_Ac_Response ResponseMod = new GoInRoom_Ac_Response()
             {
                 RoomID = room.RoomId,
                 Pnum   = room.PersonsNum
             };
             return(Ok(new AjaxResult()
             {
                 state = ResultType.success.ToString(), data = ResponseMod
             }));
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":记录删除失败:" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "记录删除失败,请重试"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 6
0
        public string Get()
        {
            //string str = "11111";
            _mysqlDbContext.addresses.Add(new Models.address
            {
                province = "上海",
                city     = "嘉定区"
            });
            _mysqlDbContext.SaveChanges();
            string str = JsonConvert.SerializeObject(_mysqlDbContext.addresses.ToList());

            return(str);
        }
Esempio n. 7
0
        public void Post([FromBody] lgview v)
        {
            MysqlDbContext db = new MysqlDbContext();
            lg             g  = new lg
            {
                ip = v.ii,
                gz = v.gg,
                bs = v.bb
            };

            db.LG.Add(g);
            db.SaveChanges();
        }
Esempio n. 8
0
 public IHttpActionResult RemoveLogs([FromBody] GameLogs_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.RoomId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var ReturnData = db.WerewlovesLogs.Where(t => t.RoomId == RequestMod.RoomId).ToList();
             db.WerewlovesLogs.RemoveRange(ReturnData);
             db.SaveChanges();
             return(Ok(new AjaxResult()
             {
                 state = ResultType.success.ToString()
             }));
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + "RemoveLogs删除失败(sql):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 9
0
 public IHttpActionResult AddLog([FromBody] Log_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.RoomId < 1 || RequestMod.LocationId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         if (string.IsNullOrEmpty(RequestMod.Content))
         {
             throw new ArgumentException("内容不可为空");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             WerewlovesLog log = new WerewlovesLog()
             {
                 CreateTime = DateTime.Now,
                 Content    = RequestMod.Content,
                 RoomId     = RequestMod.RoomId
             };
             db.WerewlovesLogs.Add(log);
             int i = db.SaveChanges();
             if (i > 0)
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.success.ToString()
                 }));
             }
             else
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.error.ToString(), message = "记录失败"
                 }));
             }
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":Log记录失败(sql):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "记录失败,请重试"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 10
0
 public IHttpActionResult QuitRoom([FromBody] QuitRoom_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.Roomid < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var room      = db.Rooms.Where(t => t.RoomId == RequestMod.Roomid & t.IsQuit == false).FirstOrDefault();
             var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.Roomid);
             var logs      = db.WerewlovesLogs.Where(t => t.RoomId == RequestMod.Roomid);
             if (room == null || roomroles == null)
             {
                 throw new ArgumentException("房间不存在");
             }
             room.IsQuit = true;
             db.RoomRoles.RemoveRange(roomroles);
             db.WerewlovesLogs.RemoveRange(logs);
             int i = db.SaveChanges();
             if (i > 0)
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.success.ToString()
                 }));
             }
             else
             {
                 LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":QuitRoom无删除记录");
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.success.ToString()
                 }));
             }
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":QuitRoom无删除记录:" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "记录删除失败,请重试"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 11
0
 public IHttpActionResult GameAgain([FromBody] ChangeSetting_Request RequestMod)
 {
     try
     {
         if (RequestMod == null)
         {
             throw new ArgumentException("非法访问");
         }
         if (RequestMod.RoomId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         var roles = RequestMod.roles.Split(',');
         foreach (var role in roles)
         {
             var Irole    = Convert.ToInt32(role);
             var rolename = Enum.GetName(typeof(Wwa.Enum.wolverole), Irole);
             if (string.IsNullOrEmpty(rolename))
             {
                 throw new ArgumentException("无此角色");
             }
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var room = db.Rooms.FirstOrDefault(t => t.RoomId == RequestMod.RoomId && t.IsQuit == false);
             if (room == null)
             {
                 throw new ArgumentException("无此房间");
             }
             room.PersonsNum = RequestMod.Pnum;
             var Vic = Enum.GetName(typeof(Wwa.Enum.Victory), RequestMod.Victory);
             if (string.IsNullOrEmpty(Vic))
             {
                 room.VictoryCondition = Wwa.Enum.Victory.屠边;
             }
             else
             {
                 room.VictoryCondition = (Wwa.Enum.Victory)Enum.Parse(typeof(Wwa.Enum.Victory), Vic);
             }
             var rolearr = roles.OrderBy(t => Guid.NewGuid()).ToList();
             var dic     = new Dictionary <int, string>();
             for (int iss = 1; iss <= rolearr.Count(); iss++)
             {
                 var      vl   = Convert.ToInt32(rolearr[iss - 1]);
                 var      name = Enum.Parse(typeof(Wwa.Enum.wolverole), vl.ToString());
                 RoomRole rr   = new RoomRole()
                 {
                     LocationId = iss,
                     RoleEnum   = (Wwa.Enum.wolverole)name,
                     Rid        = RequestMod.RoomId
                 };
                 dic.Add(iss, name.ToString());
                 db.RoomRoles.Add(rr);
             }
             int i = db.SaveChanges();
             if (i > 0)
             {
                 CreateRoom_Ac_Response returndata = new CreateRoom_Ac_Response()
                 {
                     RoomID  = RequestMod.RoomId,
                     Pnum    = RequestMod.Pnum,
                     Victory = room.VictoryCondition
                 };
                 returndata.positions = dic;
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.success.ToString(), data = returndata
                 }));
             }
             else
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.error.ToString(), message = "房间更新失败"
                 }));
             }
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + "ChangeSetting房间更新失败(数据库问题):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "房间更新失败,请联系管理员"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }