public void Initialization() { var items = new List <ShipDTO>(); var item1 = new ShipDTO { Capacity = 4, Containers = new List <string>() { "Container A", "Container B", "Container C" } }; items.Add(item1); var item2 = new ShipDTO { Capacity = 4, Containers = new List <string>() { "Container D", "Container E" } }; items.Add(item2); var truckJson = JsonConvert.SerializeObject(items); System.IO.File.WriteAllText(shipPath, truckJson); }
public Ship Map(ShipDTO ship) { try { return(new Ship { Cargo_capacity = int.TryParse(ship.Cargo_capacity, out int resultCap) ? resultCap : 0, Consumables = getConsumables(ship.Consumables), Cost_in_credits = int.TryParse(ship.Cost_in_credits, out int resultCost) ? resultCost : 0, Created = DateTimeOffset.Parse(ship.Created), Crew = int.TryParse(ship.Crew, out int resultCrew) ? resultCrew : 0, Edited = DateTimeOffset.Parse(ship.Edited), Films = ship.Films, Hyperdrive_rating = float.TryParse(ship.Hyperdrive_rating, out float resultHypRate) ? resultHypRate : 0.0f, Length = float.TryParse(ship.Length, out float resultLength) ? resultLength : 0.0f, Manufacturer = ship.Manufacturer, Max_atmosphering_speed = getAtmosphereSpeed(ship.Max_atmosphering_speed), MGLT = int.TryParse(ship.MGLT, out int resultMGLT) ? resultMGLT : 0, Model = ship.Model, Name = ship.Name, Passengers = int.TryParse(ship.Passengers, out int resultPass) ? resultCap : 0, Pilots = ship.Pilots, Starship_class = ship.Starship_class, Url = ship.Url }); }
public static string GetOperationLog(this ShipDTO entity, ShipDTO oldDTO = null) { var sb = new StringBuilder(); if (oldDTO == null) { sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Sn, entity.Sn)); sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Name, entity.Name)); sb.AppendLine(string.Format("{0}: {1}", CommonMessageResources.Description, entity.Description)); } else { if (entity.Name != oldDTO.Name) { sb.AppendLine(string.Format("{0}: {1} => {2}", CommonMessageResources.Name, oldDTO.Name, entity.Name)); } if (entity.Description != oldDTO.Description) { sb.AppendLine(string.Format("{0}: {1} => {2}", CommonMessageResources.Description, oldDTO.Description, entity.Description)); } } return(sb.ToString().TrimEnd('\r', '\n')); }
public bool CheckOverBoard(ShipDTO Ship, Board board) { foreach (var p in Ship.Location) { if (!Enumerable.Range(1, board.SIZE_X).Contains(p.X) || !Enumerable.Range(1, board.SIZE_Y).Contains(p.Y)) { return(true); } } return(false); }
public void AddShip(ShipDTO Ship, Board board, int player) { var row = Ship.Location.Select(s => new ActionShipInstall { GAME_ID = board.GAMES_ID, SHIP_ID = Ship.SHIP_ID, PLAYER = player, X = s.X, Y = s.Y }); _db.ActionShipInstall.AddRange(row); }
public bool CheckDistance(ShipDTO Ship, int max_distance, int GAME_ID, int player) { var ship1 = _db.ActionShipInstall.Where(c => c.GAME_ID == GAME_ID && c.PLAYER == player).ToList(); foreach (var p1 in ship1) { foreach (var p2 in Ship.Location) { int distance = Convert.ToInt16(Math.Sqrt(Math.Pow((p2.X - p1.X), 2) + Math.Pow((p2.Y - p1.Y), 2))); if (distance <= max_distance) { return(true); } } } return(false); }
public ShipDTO Add(ShipDTO shipDTO) { var ship = shipDTO.ToModel(); ship.Id = IdentityGenerator.NewSequentialGuid(); ship.Created = DateTime.UtcNow; if (ship.Name.IsNullOrBlank()) { throw new DefinedException(CommonMessageResources.Name_Empty); } if (_Repository.Exists(ship)) { throw new DataExistsException(string.Format(BaseMessagesResources.Ship_Exists_WithValue, ship.Name)); } var ruleName = CommonMessageResources.SerialNumberRule_Ship; var snRule = SerialNumberRuleQuerier.FindBy(ruleName); if (snRule == null) { throw new DataNotFoundException(string.Format(BaseMessagesResources.SerialNumberRule_NotExists_WithValue, ruleName)); } ship.Sn = SerialNumberGenerator.GetSerialNumber(snRule.Prefix, snRule.UseDateNumber, snRule.NumberLength); _Repository.Add(ship); #region 操作日志 var shipDto = ship.ToDto(); OperateRecorder.RecordOperation(shipDto.Sn, BaseMessagesResources.Add_Ship, shipDto.GetOperationLog()); #endregion //commit the unit of work _Repository.UnitOfWork.Commit(); return(ship.ToDto()); }
public void Update(ShipDTO shipDTO) { //get persisted item var ship = _Repository.Get(shipDTO.Id); if (ship == null) { throw new DataNotFoundException(BaseMessagesResources.Ship_NotExists); } var oldDTO = ship.ToDto(); var current = shipDTO.ToModel(); ship.Name = current.Name; ship.Description = current.Description; if (ship.Name.IsNullOrBlank()) { throw new DefinedException(CommonMessageResources.Name_Empty); } if (_Repository.Exists(ship)) { throw new DataExistsException(string.Format(BaseMessagesResources.Ship_Exists_WithValue, ship.Name)); } #region 操作日志 var shipDto = ship.ToDto(); OperateRecorder.RecordOperation(shipDto.Sn, BaseMessagesResources.Update_Ship, shipDto.GetOperationLog(oldDTO)); #endregion //commit unit of work _Repository.UnitOfWork.Commit(); }
public ActionResult EditShip(ShipDTO ship) { return(HttpHandleExtensions.AjaxCallGetResult(() => { if (ship.Id == Guid.Empty) { ship.CreatorId = GetCurrentUser().UserId; _shipService.Add(ship); this.JsMessage = MessagesResources.Add_Success; } else { _shipService.Update(ship); this.JsMessage = MessagesResources.Update_Success; } return Json(new AjaxResponse { Succeeded = true, RedirectUrl = Url.Action("Index") }); })); }
public void Register() { Console.WriteLine("Capacity(optionally, by default is 4):"); var load = Console.ReadLine(); int n; bool isNumeric = int.TryParse(load, out n); if (!isNumeric || n > 4) { n = 4; Console.WriteLine("Wrong input. Ship will be registered with capacity = 4"); } var ship = new ShipDTO { Capacity = n, Containers = new List <string>() }; var ships = ReadAll(); ships.Add(ship); var shipJson = JsonConvert.SerializeObject(ships); Save(shipJson); }
public bool CheckDupShip(int GAME_ID, int player, ShipDTO Ship, List <Ship> mShip) { return(_db.ActionShipInstall.Any(c => c.GAME_ID == GAME_ID && c.PLAYER == player && c.SHIP_ID == Ship.SHIP_ID)); }
public static Ship ToModel(this ShipDTO dto) { return(Mapper.Map <Ship>(dto)); }