public List <Core.Ship> All() { var data = new DataAccess(); service = new ShipService(data); return(service.GetShips()); }
public ResponseResult UpdateShip(string shipName, string companyName, string devicesrial, string newshipName, string newcompanyName, string newdevicesrial, string newreminder) { var result = ResponseResult.Default(); ShipService shipService = new ShipService(); try { if (string.IsNullOrEmpty(shipName)) { return(ResponseResult.Error("船体名称不能为空")); } if (string.IsNullOrEmpty(companyName)) { return(ResponseResult.Error("公司名称不能为空")); } if (string.IsNullOrEmpty(devicesrial)) { devicesrial = ""; } if (shipService.UpdateShip(shipName, companyName, devicesrial, newshipName, newcompanyName, newdevicesrial, newreminder)) { return(ResponseResult.Success("修改成功")); } else { return(ResponseResult.Error("修改失败")); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
public async Task <ShipService> UpdateAsync(ShipService shipService) { var updatedShipService = _shipServiceContext.ShipService.Update(shipService); await _shipServiceContext.SaveChangesAsync(); return(updatedShipService.Entity); }
public async Task <ShipService> AddAsync(ShipService shipService) { var shipServiceToAdd = (await _shipServiceContext.ShipService.AddAsync(shipService)).Entity; await _shipServiceContext.SaveChangesAsync(); return(shipServiceToAdd); }
public void ExecuteRequest() { ShipService service = new ShipService(); try { if (_request.RequestedShipment == null) { return; } _reply = service.processShipment(_request); foreach (CompletedPackageDetail packageDetail in _reply.CompletedShipmentDetail.CompletedPackageDetails) { _trackingIds = packageDetail.TrackingIds; if (packageDetail.PackageRating != null && packageDetail.PackageRating.PackageRateDetails != null) { _packageRateDetails = packageDetail.PackageRating.PackageRateDetails; } else { Console.WriteLine("No Rating information returned.\n"); } _completedPackageDetail = packageDetail; _completedShipmentDetail = _reply.CompletedShipmentDetail; } } catch (SoapException e) { } catch (Exception e) { } }
public ResponseResult <Ship> GetShipBySCN(string shipName, string companyName) { var result = ResponseResult <Ship> .Default(); ShipService shipService = new ShipService(); List <Ship> ships = new List <Ship>(); try { if (string.IsNullOrEmpty(shipName)) { return(ResponseResult <Ship> .Error("船体名称不能为空")); } if (string.IsNullOrEmpty(companyName)) { return(ResponseResult <Ship> .Error("公司名称不能为空")); } else { ships = shipService.GetShipSCN(shipName, companyName); result = ResponseResult <Ship> .Success(ships, "获取船体信息成功"); if (ships.Count == 0) { result = ResponseResult <Ship> .Error("无记录"); } } } catch (System.Exception ex) { result = ResponseResult <Ship> .Error(ex.Message); } return(result); }
public ResponseResult DeleteShip(string shipName, string companyName) { var result = ResponseResult.Default(); ShipService shipService = new ShipService(); try { if (string.IsNullOrEmpty(shipName)) { return(ResponseResult.Error("船体名称不能为空")); } if (string.IsNullOrEmpty(companyName)) { return(ResponseResult.Error("公司名称不能为空")); } if (shipService.DeleteShip(shipName, companyName)) { return(ResponseResult.Success("删除成功")); } else { return(ResponseResult.Error("删除失败")); } } catch (System.Exception ex) { result = ResponseResult.Error(ex.Message); } return(result); }
PlaceShip_WHEN_InvokedAndCollisionWithShipDetected_THEN_ReturnSuccessFalse(int row, int column, int shipLength, Direction direction) { var mapRepoMock = new Mock <IRepository <Map> >(); var mapWithShips = new Map(10, 10); mapWithShips.Fields[row][column + 1].Ship = new Ship(4); mapWithShips.Fields[row][column + 2].Ship = new Ship(4); mapWithShips.Fields[row][column + 3].Ship = new Ship(4); mapWithShips.Fields[row][column + 4].Ship = new Ship(4); mapWithShips.Fields[row - 1][column].Ship = new Ship(4); mapWithShips.Fields[row][column].Ship = new Ship(4); mapWithShips.Fields[row + 1][column].Ship = new Ship(4); mapWithShips.Fields[row + 2][column].Ship = new Ship(4); mapWithShips.Fields[row - 1][column - 1].Ship = new Ship(4); mapWithShips.Fields[row][column - 1].Ship = new Ship(4); mapWithShips.Fields[row + 1][column - 1].Ship = new Ship(4); mapWithShips.Fields[row + 2][column - 1].Ship = new Ship(4); mapRepoMock.SetupGet(c => c.Entity).Returns(mapWithShips); var shipService = new ShipService(mapRepoMock.Object); var ship = new Ship(shipLength) { Direction = direction }; var result = shipService.PlaceShip(row, column, ship); result.Success.Should().BeFalse(); result.Error.Should().BeEquivalentTo("There is already ship on provided coordinates"); }
public async Task <InvoiceReadModel> GetInvoice(string invoiceId) { Invoice invoice = await _eventRepository.GetByIdAsync(new InvoiceId(invoiceId)); var taskInvoiceLines = Task.WhenAll(invoice.Lines.Select(async x => { var getShipTask = _shipRepository.GetShip(x.ShipId.ToString()); var getServiceTask = _shipServiceRepository.GetShipService(x.ServiceId.ToString()); await Task.WhenAll(getShipTask, getServiceTask); Ship ship = getShipTask.Result; ShipService service = getServiceTask.Result; return(new InvoiceLineReadModel { Description = $"Service: {service.Name} applied for ship: {ship.Name}", Price = service.Price }); })); var taskCustomer = Task.Run(async() => { Customer foundCustomer = await _customerRepository.GetCustomerAsync(invoice.CustomerId.ToString()); CustomerReadModel readModel = new CustomerReadModel { Address = foundCustomer.Address, Email = foundCustomer.Email, PostalCode = foundCustomer.PostalCode, Residence = foundCustomer.Residence }; return(readModel); }); var taskRental = Task.Run(async() => { Rental foundRental = await _rentalRepository.GetRental(invoice.RentalId.ToString()); RentalReadModel readModel = new RentalReadModel { Price = foundRental.Price }; return(readModel); }); await Task.WhenAll(taskInvoiceLines, taskCustomer, taskRental); var customer = await taskCustomer; var lines = await taskInvoiceLines; var rental = await taskRental; return(new InvoiceReadModel { Customer = customer, Lines = lines, Rental = rental, TotalPrice = rental.Price + lines.Sum(x => x.Price) }); }
public override void CreateShipment() { ShipReply result = null; ProcessShipmentRequest request = CreateShipmentRequest(); try { ShipService service = new ShipService(); service.Url = Url; ProcessShipmentReply reply = service.processShipment(request); if ((reply.HighestSeverity != NotificationSeverityType.ERROR) && (reply.HighestSeverity != NotificationSeverityType.FAILURE)) { result = SetShipmentReply(reply); } else { if (reply.Notifications.Length > 0) { ErrorMessage = string.Format("{0} {1}", reply.Notifications[0].Code, reply.Notifications[0].Message); } } ShipReplyEx = result; } catch (SoapException e) { Debug.WriteLine(e.Detail.InnerText); } catch (Exception e) { Debug.WriteLine(e.Message); } // return result; }
public void TestShippingByStore_Seven_1_Order_Family_2_Orders() { //arrange var target = new ShipService(); var orders = new List<Order> { new Order{ StoreType= StoreType.Seven, Id=1}, new Order{ StoreType= StoreType.Family, Id=2}, new Order{ StoreType= StoreType.Family, Id=3}, }; //set stub by simple factory's internal setter var stubSeven = Substitute.For<IStoreService>(); SimpleFactory.SetSevenService(stubSeven); var stubFamily = Substitute.For<IStoreService>(); SimpleFactory.SetFamilyService(stubFamily); //act target.ShippingByStore(orders); //assert //ShipService should invoke SevenService once and FamilyService twice stubSeven.Received(1).Ship(Arg.Is<Order>(x => x.StoreType == StoreType.Seven)); stubFamily.Received(2).Ship(Arg.Is<Order>(x => x.StoreType == StoreType.Family)); }
public void TestShippingByStore_Seven_1_Order_Family_2_Orders() { var target = new ShipService(); var orders = new List <Order> { new Order { StoreType = StoreType.Seven, Id = 1 }, new Order { StoreType = StoreType.Family, Id = 2 }, new Order { StoreType = StoreType.Family, Id = 3 }, }; var stubSeven = Substitute.For <IStoreService>(); SimpleFactory.SetSevenService(stubSeven); var stubFamily = Substitute.For <IStoreService>(); SimpleFactory.SetFamilyService(stubFamily); target.ShippingByStore(orders); stubSeven.Received(1).Ship(Arg.Is <Order>(a => a.StoreType == StoreType.Seven)); stubFamily.Received(2).Ship(Arg.Is <Order>(a => a.StoreType == StoreType.Family)); }
public ResponseResult <Ship> GetAllShip(string companyId) { var result = ResponseResult <Ship> .Default(); ShipService shipService = new ShipService(); List <Ship> ships = new List <Ship>(); try { if (string.IsNullOrEmpty(companyId)) { return(ResponseResult <Ship> .Error("公司ID不能为空")); } else { ships = shipService.GetAllShip(Convert.ToInt32(companyId)); result = ResponseResult <Ship> .Success(ships, "获取船体信息成功"); } if (ships.Count == 0) { result = ResponseResult <Ship> .Error("无记录"); } } catch (System.Exception ex) { result = ResponseResult <Ship> .Error(ex.Message); } return(result); }
private void AddUpsSecurity(ShipService upsShipService) { var upss = new UPSSecurity(); AddUpsServiceAccessToken(upss); AddUserNameToken(upss); upsShipService.UPSSecurityValue = upss; }
public async Task <ShipService> CreateShipService(ShipService shipService) { var addedShipService = await _shipServiceService.AddAsync(shipService); await _messagePublisher.PublishMessageAsync(MessageTypes.ServiceCreated, shipService); return(addedShipService); }
public void Setup() { shipOwnerId = 1; repositoryMock = new Mock <IBaseRepository <Ship> >(); shipOwnerRepositoryMock = new Mock <IFindRepository <ShipOwner> >(); loggerMock = new Mock <IApplicationLogger <ShipService> >(); service = new ShipService(repositoryMock.Object, shipOwnerRepositoryMock.Object, loggerMock.Object); }
public ShipmentResponse CallUPSShipmentRequest(string serviceCode, int ShipmentID) { //var dbShipment = ShipmentModule.GetShipmentByID(ShipmentID); var shipmentDetails = ShipmentModule.GetShipmentShipmentDetails(ShipmentID); var shpSvc = new ShipService(); var shipmentRequest = new ShipmentRequest(); AddUpsSecurity(shpSvc); var request = new RequestType(); String[] requestOption = { "1" }; //{ "nonvalidate" }; request.RequestOption = requestOption; shipmentRequest.Request = request; var shipment = new ShipmentType(); shipment.Description = "Ship webservice example"; AddShipper(shipment); AddShipFromAddress(shipment); AddShipToAddress(shipment); AddBillShipperAccount(shipment); //AddPaymentInformation(shipment); var service = new ServiceType(); service.Code = serviceCode; shipment.Service = service; PackageType[] pkgArray; pkgArray = new PackageType[shipmentDetails.Count]; var i = 0; foreach (var box in shipmentDetails) { AddPackage(box.UnitWeight.Value, Convert.ToInt32(box.UnitPrice), box.DimensionH.Value, box.DimensionD.Value, box.DimensionL.Value, PackagingTypeCode, "USD", pkgArray, i); i = i + 1; } shipment.Package = pkgArray; var labelSpec = new LabelSpecificationType(); var labelStockSize = new LabelStockSizeType(); labelStockSize.Height = "3"; labelStockSize.Width = "2"; labelSpec.LabelStockSize = labelStockSize; var labelImageFormat = new LabelImageFormatType(); labelImageFormat.Code = "GIF";//"SPL"; labelSpec.LabelImageFormat = labelImageFormat; shipmentRequest.LabelSpecification = labelSpec; shipmentRequest.Shipment = shipment; var shipmentResponse = shpSvc.ProcessShipment(shipmentRequest); return(shipmentResponse); }
/// <summary> /// 获取物流细节 /// </summary> /// <param name="ctx"></param> /// <param name="notices"></param> /// <returns></returns> public static Dictionary <string, T> GetLogisticsDetail <T>(Context ctx, List <DeliveryNotice> notices) { string messages = ""; Dictionary <string, T> dict = new Dictionary <string, T>(); // Set this to true to process a COD shipment and print a COD return Label if (notices != null && notices.Count > 0) { foreach (var notice in notices) { ProcessShipmentRequest request = CreateShipmentRequest(notice); LogXML("DeliveryNoitceNo:" + notice.FBillNo + " Request ", request, typeof(ProcessShipmentRequest)); ShipService service = new ShipService(); if (usePropertyFile()) { service.Url = getProperty("endpoint"); } // try { // Call the ship web service passing in a ProcessShipmentRequest and returning a ProcessShipmentReply ProcessShipmentReply reply = service.processShipment(request); LogXML("DeliveryNoitceNo:" + notice.FBillNo + " Reply ", reply, typeof(ProcessShipmentReply)); messages += GetNotifications(reply); if ((reply.HighestSeverity != NotificationSeverityType.ERROR) && (reply.HighestSeverity != NotificationSeverityType.FAILURE)) { notice.TraceEntry = GetShipmentReply(reply); //LogXML(reply, typeof(ProcessShipmentReply)); } RecordNotifications(ctx, reply); } catch (SoapException ex) { SynchroDataHelper.WriteSynchroLog(ctx, SynchroDataType.DeliveryNoticeBill, ex.Message + System.Environment.NewLine + ex.StackTrace); } catch (Exception ex) { SynchroDataHelper.WriteSynchroLog(ctx, SynchroDataType.DeliveryNoticeBill, ex.Message + System.Environment.NewLine + ex.StackTrace); } } } HttpResponseResult result = new HttpResponseResult(); result.Message = messages; dict.Add("result", (T)(Object)result); dict.Add("notices", (T)(Object)notices); return(dict); }
public async Task DeleteAsync(Guid id) { var shipServiceToDelete = new ShipService() { Id = id }; _shipServiceContext.Entry(shipServiceToDelete).State = EntityState.Deleted; await _shipServiceContext.SaveChangesAsync(); }
public void PlaceShip_WHEN_InvokedAndNoMapFound_THEN_ThrowsMapNotInitializedException() { var mapRepoMock = new Mock <IRepository <Map> >(); mapRepoMock.SetupGet(c => c.Entity).Returns((Map)null); var shipService = new ShipService(mapRepoMock.Object); var act = new Func <PlacingShipResult>(() => shipService.PlaceShip(4, 0, new Ship(4))); act.Should().ThrowExactly <MapNotInitializedException>(); }
public async Task <ShipService> UpdateShipService(Guid id, ShipService shipService) { var shipServiceToUpdate = await _shipServiceService.GetAsync(id); shipServiceToUpdate.Name = shipService.Name; shipServiceToUpdate.Price = shipService.Price; await _shipServiceService.UpdateAsync(shipServiceToUpdate); await _messagePublisher.PublishMessageAsync(MessageTypes.ServiceUpdated, shipService); return(shipServiceToUpdate); }
public virtual XElement ToElement(bool includeHeader) { var package = new XElement("Package", new XElement("TrackingNumber", TrackingNumber.ToStringWithNonSpace()), new XElement("ShipCarrier", ShipCarrier.ToStringWithNonSpace()), new XElement("ShipService", ShipService.ToStringWithNonSpace()), new XElement("ItemList", from item in ItemList select item.ToElement(false))); return(package); }
public void StartGame() { board = new Board(GameConfig.BoardWidth, GameConfig.BoardHeight); sc = new ShipService(board); view = new ConsoleView(); // Place 3 ships on the board board.AddShip(sc.CreateRandomShip(Ship.Type.BATTLESHIP)); board.AddShip(sc.CreateRandomShip(Ship.Type.DESTROYER)); board.AddShip(sc.CreateRandomShip(Ship.Type.DESTROYER)); ExecuteTurn(true); }
PlaceShip_WHEN_InvokedAndCollisionWithBorderDetected_THEN_ReturnSuccessFalse(int row, int column, int shipLength, Direction direction) { var mapRepoMock = new Mock <IRepository <Map> >(); mapRepoMock.SetupGet(c => c.Entity).Returns(new Map(10, 10)); var shipService = new ShipService(mapRepoMock.Object); var ship = new Ship(shipLength) { Direction = direction }; var result = shipService.PlaceShip(row, column, ship); result.Success.Should().BeFalse(); result.Error.Should().BeEquivalentTo("Ship cannot exceed map dimensions"); }
public async static Task Seed(IShipServiceManager shipServiceManager) { var shipServices = new List <ShipService>(); var refuelingService = new ShipService() { Id = Guid.Parse("ff9f7c8c-92b6-4863-8451-de7c94389d53"), Name = "RefuelingService", Price = 10.25 }; shipServices.Add(refuelingService); var electricityService = new ShipService() { Id = Guid.Parse("adfe1a0c-28fa-4e0e-a0c1-524bf1bb3624"), Name = "ElectricityService", Price = 25.25 }; shipServices.Add(electricityService); var loadingService = new ShipService() { Id = Guid.Parse("6d96ec17-9596-434d-a39f-3227cdbefda2"), Name = "LoadingService", Price = 15.33 }; shipServices.Add(loadingService); var unloadingService = new ShipService() { Id = Guid.Parse("5c80d53c-91fa-4578-937d-4afb214ff960"), Name = "UnloadingService", Price = 15.34 }; shipServices.Add(unloadingService); foreach (var shipService in shipServices) { await shipServiceManager.CreateShipService(shipService); } Console.WriteLine("Seed completed"); }
PlaceShip_WHEN_InvokedWithLeftOrRightDirection_THEN_ReturnShipWithFieldsNextToEachOtherInSameRow(int row, int column, int shipLength, Direction direction) { var mapRepoMock = new Mock <IRepository <Map> >(); mapRepoMock.SetupGet(c => c.Entity).Returns(new Map(10, 10)); var shipService = new ShipService(mapRepoMock.Object); var ship = new Ship(shipLength) { Direction = direction }; var result = shipService.PlaceShip(row, column, ship); result.Error.Should().BeNullOrEmpty(); result.Ship.Coordinates.Count.Should().Be(shipLength); result.Ship.Coordinates.Select(c => c.Row).Should().AllBeEquivalentTo(row); result.Ship.Coordinates.Select(c => c.Column).Should().OnlyHaveUniqueItems(); }
public async Task <IActionResult> Post([FromBody] ShipService shipService) { IActionResult response = null; if (shipService == null || shipService.Id == null || shipService.Id == Guid.Empty) { response = NotFound(); } else { var createdShipService = await _shipServiceManager.CreateShipService(shipService); response = Ok(createdShipService); } return(response); }
public async Task <IActionResult> Put(Guid id, [FromBody] ShipService shipService) { IActionResult response = null; if (shipService == null) { response = NotFound(); } else { var updatedShipService = await _shipServiceManager.UpdateShipService(id, shipService); response = Ok(updatedShipService); } return(response); }
static void Main(string[] args) { // Set this to true to process a COD shipment and print a COD return Label bool isCodShipment = true; ProcessShipmentRequest request = CreateShipmentRequest(isCodShipment); LogXML(request, typeof(ProcessShipmentRequest)); // ShipService service = new ShipService(); //if (usePropertyFile()) // { // service.Url = getProperty("endpoint"); // } // try { // Call the ship web service passing in a ProcessShipmentRequest and returning a ProcessShipmentReply ProcessShipmentReply reply = service.processShipment(request); // if ((reply.HighestSeverity != NotificationSeverityType.ERROR) && (reply.HighestSeverity != NotificationSeverityType.FAILURE)) { ShowShipmentReply(isCodShipment, reply); //LogXML(reply, typeof(ProcessShipmentReply)); } ShowNotifications(reply); } catch (SoapException e) { Console.WriteLine(e.Detail.InnerText); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press any key to quit !"); Console.ReadKey(); }
public ActionResult GetShip(string ship, string company) { string json = null; if (ship == null && company == null) { string companyId = Session["CompanyId"].ToString(); json = new ShipService().GetAllShip(Convert.ToInt32(companyId)); } if (!string.IsNullOrEmpty(ship) && !string.IsNullOrEmpty(company)) { string companyName = company; string shipName = ship; json = new ShipService().GetShipBySCN(shipName, companyName); } else if (!string.IsNullOrEmpty(company)) { string companyName = company; json = new ShipService().GetShipByCN(companyName); } return(Content(json)); }
RandomlyPlaceShip_WHEN_Invoked_THEN_ReturnRandomlyPlacedShip(int length) { var mapRepoMock = new Mock <IRepository <Map> >(); var mapWithShips = new Map(10, 10); mapWithShips.Fields[0][1].Ship = new Ship(4); mapWithShips.Fields[0][2].Ship = new Ship(4); mapWithShips.Fields[0][3].Ship = new Ship(4); mapWithShips.Fields[0][4].Ship = new Ship(4); mapWithShips.Fields[0][0].Ship = new Ship(4); mapWithShips.Fields[1][0].Ship = new Ship(4); mapWithShips.Fields[2][0].Ship = new Ship(4); mapWithShips.Fields[3][0].Ship = new Ship(4); mapRepoMock.SetupGet(c => c.Entity).Returns(new Map(10, 10)); var shipService = new ShipService(mapRepoMock.Object); var result = shipService.RandomlyPlaceShip(length); result.Success.Should().BeTrue(); result.Ship.Should().NotBeNull(); result.Ship.Coordinates.Count.Should().Be(length); }
private void initialize() { svc = new ShipService(); svc.Url = Settings.Endpoint; shipper = new Party(); shipper.Contact = new Contact(); shipper.Contact.CompanyName = Settings.CompanyName; shipper.Contact.PhoneNumber = Settings.Telephone; shipper.Contact.EMailAddress = Settings.Email; shipper.Address = new Address(); var l1 = Settings.AddressLine1; var l2 = Settings.AddressLine2; if (string.IsNullOrEmpty(l2)) { shipper.Address.StreetLines = new string[1] { l1 }; } else { shipper.Address.StreetLines = new string[2] { l1, l2 }; } shipper.Address.City = Settings.City; shipper.Address.StateOrProvinceCode = Settings.State; shipper.Address.PostalCode = Settings.PostalCode; shipper.Address.CountryCode = Settings.CountryCode; shipper.AccountNumber = Settings.AccountNumber; auth = new WebAuthenticationDetail(); auth.UserCredential = new WebAuthenticationCredential(); auth.UserCredential.Key = Settings.APIKey; auth.UserCredential.Password = Settings.Password; clientDetail = new ClientDetail(); clientDetail.AccountNumber = Settings.AccountNumber; clientDetail.MeterNumber = Settings.MeterNumber; }