public ActionResult ShipInstall([FromBody] ShipInstall model) { return(new JsonResult(_service.ShipInstall(model))); }
public Response ShipInstall(ShipInstall model) { var board = _unitOfWork.Games.GetGameByID(model.GAME_ID); var mShip = _unitOfWork.Ships.GetAll().ToList(); if (board == null) { return(new Response { ResponseCode = "1", Message = "ยังไม่สร้าง board" }); } else if (board.STATUS != GameCodes.Status.INSTALL || _unitOfWork.ActionShipInstalls.CheckShipOver(board.GAMES_ID, model.PLAYER, mShip)) { return(new Response { ResponseCode = "1", Message = "เกมนี้ไม่สามารถวางเรือได้แล้ว" }); } var rShip = model.Ship; //var rShip = JsonConvert.DeserializeObject<List<ShipDTO>>(jsonShip); if (_unitOfWork.ActionShipInstalls.CheckOverBoard(rShip, board)) { return(new Response { ResponseCode = "1", Message = "วางเรือเกินพื้นที่ 5*5 ช่อง" }); } if (_unitOfWork.ActionShipInstalls.CheckDistance(rShip, 1, model.GAME_ID, model.PLAYER)) { return(new Response { ResponseCode = "1", Message = "วางเรือหางกัน 1 ช่อง" }); } if (_unitOfWork.ActionShipInstalls.CheckDupShip(model.GAME_ID, model.PLAYER, rShip, mShip)) { return(new Response { ResponseCode = "1", Message = "SHIP_ID Duplicate!" }); } _unitOfWork.ActionShipInstalls.AddShip(rShip, board, model.PLAYER); _unitOfWork.SaveChanges(); AllShipOK(board, model.GAME_ID, mShip); return(new Response { ResponseCode = "0", Data = board }); }