/// <summary> /// Saves the settings the user has selected/input. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save_Button_Click(object sender, RoutedEventArgs e) { //grab all values from window string saveDir = txtSaveLocation.Text; string labelPrinter = comboPrinters.SelectedItem as string; //first check that a company has been selected if (comboCompanyAddress.SelectedItem != null) { CompanyAddressModel comp = (CompanyAddressModel)comboCompanyAddress.SelectedItem; int compId = comp.Id; //save to settings for persistence if (saveDir != null & labelPrinter != null) { settings.CompanyAddressId = compId; settings.SaveFileDir = saveDir; settings.LabelPrinter = labelPrinter; settings.Save(); //return to main menu Switcher.Switch(new MainMenu()); } else { MessageBox.Show("A label printer and save file directory must be selected."); } } else { MessageBox.Show("A company address must be selected."); } }
/// <summary> /// Overloaded constructor passing in a CompanyAddressModel to edit one. /// </summary> /// <param name="comp">CompanyAddressModel to be edited.</param> public CompanyViewModel(CompanyAddressModel comp) { StateModels = new List <StateModel>(); CurrentCompanyAddress = comp; PopulateLists(); }
/// <summary> /// Edits the currently selected company address. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editShipFrBtn_Click(object sender, RoutedEventArgs e) { if (comboCompanyAddress.SelectedItem is CompanyAddressModel) { //grab selected item. CompanyAddressModel companyAddress = (CompanyAddressModel)comboCompanyAddress.SelectedItem; //instantiate new CompanyAddressWin.xaml and pass in selected comp address CompanyAddressWin compWindow = new CompanyAddressWin(companyAddress, Utilities.DbQuery.Edit); compWindow.titleLabel.Content = "Edit Company Ship From"; //show the window. compWindow.ShowDialog(); if (compWindow.DialogResult == true) //warehouse edit is successful { //save updated warehouse to database. MessageBox.Show("Company Address successfully saved."); PopulateGUI(); } else //warehouse edit is unsuccessful { //inform user nothing was done. MessageBox.Show("Unable to save the Company Address."); } } }
/// <summary> /// Overloaded constructor for editing an existing company address. /// </summary> /// <param name="comp"></param> public CompanyAddressWin(CompanyAddressModel comp, Utilities.DbQuery dbQuery) { InitializeComponent(); compAddress = comp; compVM = new CompanyViewModel(compAddress); DbQuery = dbQuery; PopulateGUI(); }
public static CompanyAddressEntity ToEntity(this CompanyAddressModel addressModel) { return(new CompanyAddressEntity { Country = addressModel.Country, City = addressModel.City, PostCode = addressModel.PostCode, Street = addressModel.Street, StreetNumber = addressModel.StreetNumber }); }
/// <summary> /// When a CompanyAddress is selected, it displays the full address for the user to view it all, and enables the deletion and editing of the selected address. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboCompanyAddress_Selected(object sender, RoutedEventArgs e) { if (comboCompanyAddress.SelectedItem is CompanyAddressModel) { CompanyAddressModel companyAddress = settingsVM.CompanyAddresses[comboCompanyAddress.SelectedIndex]; txtBlockFullCompanyAddress.Text = companyAddress.LegalEntityName + "\n" + companyAddress.CompanyName + "\n" + companyAddress.AddressLine1 + "\n" + companyAddress.AddressLine2 + "\n" + companyAddress.AddressLine3 + "\n" + companyAddress.City + ", " + companyAddress.StateAbrv + " " + companyAddress.ZipCode;; editShipFrBtn.IsEnabled = true; deleteShipFrBtn.IsEnabled = true; } }
public IActionResult SaveCompanyAddress([FromBody] CompanyAddressModel companyAddressModel) { if (!ModelState.IsValid) { return(new ValidationActionResult(ModelState)); } CompanyModel model = companyService.SaveAddressDetails(companyAddressModel); companyService.MapRelativeLogoPath(model, configuration, HttpContext.Request.CurrentUrl()); return(Ok(model)); }
/// <summary> /// Allows for a query to be performed on the database to a CompanyAddress Entity. /// </summary> /// <param name="companyAddress">Modified CompanyAdrressModel to be passed to database.</param> /// <param name="dbQuery">The type of query to be performed on the database.</param> /// <returns>If successfully added to Db return True. </returns> public bool CompanyAddressToDb(CompanyAddressModel companyAddress, Utilities.DbQuery dbQuery) { if (companyAddress != null) { //edit companyAddress to db using (var db = new Models.AppContext()) { //instantiate new CompanyAddress entity and fill fields CompanyAddress company = new CompanyAddress() { Id = companyAddress.Id, LegalEntityName = companyAddress.LegalEntityName, CompanyName = companyAddress.CompanyName, AddressLine1 = companyAddress.AddressLine1, AddressLine2 = companyAddress.AddressLine2, AddressLine3 = companyAddress.AddressLine3, City = companyAddress.City, ZipCode = companyAddress.ZipCode, State = db.States.Where(s => s.Id == companyAddress.StateId).FirstOrDefault() }; //perform correct DB query depending on what was passed in as dbentry. switch (dbQuery) { case Utilities.DbQuery.Add: db.CompanyAddresses.Add(company); break; case Utilities.DbQuery.Edit: db.Entry(company).State = System.Data.Entity.EntityState.Modified; break; case Utilities.DbQuery.Delete: CompanyAddress compDelete = db.CompanyAddresses.Find(company.Id); db.CompanyAddresses.Remove(compDelete); break; } //save DbContext db.SaveChanges(); return(true); } } else { return(false); } }
public CompanyModel SaveAddressDetails(CompanyAddressModel companyAddressModel) { var company = unitOfWork.Company.GetById(o => o.Id == companyAddressModel.CompanyId, "PhysicalAddress, PostalAddress"); if (company == null) { throw new ResponseValidationException(ResponseMessage.ToError("Company you trying to update does not exist.")); } companyAdapter.UpdateAddressDetails(company, companyAddressModel); unitOfWork.Company.Update(company); unitOfWork.Save(); return(companyBuilder.BuildToCompanyModel(unitOfWork.Company.GetById(o => o.Id == companyAddressModel.CompanyId))); }
/// <summary> /// Deletes the currently selected company address. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteShipFrBtn_Click(object sender, RoutedEventArgs e) { //grab selected item. CompanyAddressModel companyAddress = (CompanyAddressModel)comboCompanyAddress.SelectedItem; //companyviewModel to Delete item. CompanyViewModel compVm = new CompanyViewModel(companyAddress); if (compVm.CompanyAddressToDb(companyAddress, Utilities.DbQuery.Delete)) { MessageBox.Show(companyAddress.CompanyName + " ship from address successfully deleted."); } else { MessageBox.Show("Unable to delete" + companyAddress.CompanyName + " ship from address."); } }
/// <summary> /// Return a company address /// </summary> /// <param name="email"></param> /// <param name="rooturl"></param> /// <param name="encodedId"></param> /// <param name="id"></param> /// <returns></returns> public async Task <CompanyAddressModel> GetCompanyAddress(string email, string rooturl, string encodedId, int id) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(rooturl) || string.IsNullOrEmpty(encodedId) || id <= 0) { return(null); } string queryname = WebTasksTypeConstants.GetCompanyAddress; string queryterms = WebApiServices.GetJsonQuerySearchTermsCompanyAddressId(id.ToString()); string url = $"{rooturl}api/webtasks?queryname={queryname}&queryterms={queryterms}"; CompanyAddressModel result = null; LoggingService service = new LoggingService(); var stopwatch = new Stopwatch(); try { var response = await new WebApiServices().GetData(url, encodedId); if (!string.IsNullOrEmpty(response)) { result = new SerializerServices() .DeserializeObject <CompanyAddressModel>(response.NormalizeJsonString()); } } catch (Exception ex) { service.TrackException(ex); throw; } finally { stopwatch.Stop(); var properties = new Dictionary <string, string> { { "UserEmail", email }, { "WebServicesEndpoint", rooturl }, { "EncodedId", encodedId }, { "CompanyAddressId", id.ToString() } }; service.TrackEvent(LoggingServiceConstants.GetCompanyAddress, stopwatch.Elapsed, properties); } return(result); }
public void UpdateAddressDetails(Company company, CompanyAddressModel addressModel) { if (company.PostalAddressId == null) { company.PostalAddress = addressBuilder.Build(addressModel.PostalAddress); } else { addressAdapter.Update(company.PostalAddress, addressModel.PostalAddress); } if (company.PhysicalAddress == null) { company.PhysicalAddress = addressBuilder.Build(addressModel.PhysicalAddress); } else { addressAdapter.Update(company.PhysicalAddress, addressModel.PhysicalAddress); } }
/// <summary> /// Opens a new window that allows the user to add a new ShipFrom Company Address to the databse. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void newShipFrbtn_Click(object sender, RoutedEventArgs e) { //open a new window for adding a new Company Ship From. CompanyAddressModel comp = new CompanyAddressModel(); CompanyAddressWin compWindow = new CompanyAddressWin(comp, Utilities.DbQuery.Add); compWindow.titleLabel.Content = "Add New Company Ship From"; compWindow.ShowDialog(); if (compWindow.DialogResult == true) { //save updated warehouse to database. MessageBox.Show("Company Address successfully saved."); PopulateGUI(); } else { //inform user nothing was done. MessageBox.Show("Unable to save the Company Address."); } }
/// <summary> /// Update the specified company address /// </summary> /// <param name="address"></param> /// <param name="encodedId"></param> /// <param name="rooturl"></param> /// <returns></returns> public async Task <bool> UpdateCompanyAddress(CompanyAddressModel address, string encodedId, string rooturl) { if (string.IsNullOrEmpty(address?.Postcode) || string.IsNullOrEmpty(address.AddressLine1) || string.IsNullOrEmpty(encodedId) || string.IsNullOrEmpty(rooturl)) { return(false); } bool result; string url = $"{rooturl}api/webtasks?formname={RoutingTasksTypeConstants.UpdateCompanyAddress}&useRoutingController=true"; LoggingService service = new LoggingService(); var stopwatch = new Stopwatch(); try { string payload = new SerializerServices().SerializeObject(address); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await new WebApiServices().PutData(url, content, encodedId); result = response.IsSuccessStatusCode; } catch (Exception ex) { service.TrackException(ex); throw; } finally { stopwatch.Stop(); var properties = new Dictionary <string, string> { { "CompanyAddress", $"{address.Postcode} {address.AddressLine1}" }, { "EncodedId", encodedId }, { "WebServicesEndpoint", rooturl } }; service.TrackEvent(LoggingServiceConstants.UpdateCompanyAddress, stopwatch.Elapsed, properties); } return(result); }
/// <summary> /// Gets company address model /// </summary> /// <param name="currentOrganization">The current organization.</param> /// <returns>CompanyAddressModel.</returns> public static CompanyAddressModel GetShippingBillingForOrganization(Organization currentOrganization) { var retVal = new CompanyAddressModel { CurrentOrganization = currentOrganization }; if (currentOrganization != null) { if (currentOrganization.Addresses.Count > 0) { retVal.BillingAddress = currentOrganization.Addresses.FirstOrDefault(x => x.Name.Contains(DefaultBilling)); retVal.ShippingAddress = currentOrganization.Addresses.FirstOrDefault(x => x.Name.Contains(DefaultShipping)); } retVal.OthersAddresses = currentOrganization.Addresses.Where(addr => !addr.Name.Contains(DefaultShipping) && !addr.Name.Contains(DefaultBilling)) .ToArray(); } return(retVal); }
private CompanyAddressViewModel GetAddressViewModel(CompanyAddressModel model) { return(_viewModelFactory.CreateInstance <CompanyAddressViewModel, CompanyAddressModel>(model)); }
/// <summary> /// Sends a list of boxes to the default label printer to be printed. /// </summary> /// <param name="boxestoPrint">List of boxes to print</param> /// <param name="amzWarehouse">The Amazon Fulfillment Center for the box label</param> /// <param name="companyAddress">The Company Address for the box label</param> public void ReprintLabels(List <FBABox> boxestoPrint, AmzWarehouseModel amzWarehouse, CompanyAddressModel companyAddress, int totalBoxCount) { //reinitialize the labelfactory LabelFactory = new LabelFactory(boxestoPrint, amzWarehouse, companyAddress, totalBoxCount); //grab default label printer string labelPrinter = Properties.Settings.Default.LabelPrinter; //send each label to the printer. foreach (var label in LabelFactory.BoxLabels) //send each BoxLabel to printer. { RawPrinterHelper.SendStringToPrinter(labelPrinter, label.ZPLCommand); } }
/// <summary> /// Reprints FBA Box labels to PDF using labelry.com API service. /// </summary> /// <param name="boxestoPrint">List of FBABox to be reprinted</FBABox></param> /// <param name="amzWarehouse">Ship To Amazon Warehouse</param> /// <param name="companyAddress">Ship From Company Address</param> /// <param name="totalBoxCount">Total boxes in the shipment</param> /// <param name="shipmentID">The Shipment Id of the boxes.</param> public void ReprintToPDF(List <FBABox> boxestoPrint, AmzWarehouseModel amzWarehouse, CompanyAddressModel companyAddress, int totalBoxCount, string shipmentID) { //empty string to fill zpl command string zpl = ""; string boxesPrinted = ""; //instantiate new LabelFactory with passed in parameters. LabelFactory = new LabelFactory(boxestoPrint, amzWarehouse, companyAddress, totalBoxCount); //fill in string for ZPL command foreach (ZPLLabel label in LabelFactory.BoxLabels) { zpl += label.ZPLCommand; boxesPrinted += label.Box.BoxNumber + "-"; } //make a savepath string string filePath = Properties.Settings.Default.SaveFileDir + "\\" + shipmentID + "_BOXES_" + boxesPrinted + " _Reprinted_Labels.pdf"; //get string in UTF8 bytes byte[] zplByte = Encoding.UTF8.GetBytes(zpl); // instantiate request object var request = (HttpWebRequest)WebRequest.Create("http://api.labelary.com/v1/printers/8dpmm/labels/4x8/"); request.Method = "POST"; request.Accept = "application/pdf"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = zplByte.Length; //adding headers request.Headers.Add("X-Rotation:90"); //rotate labels 90 degrees request.Headers.Add("X-Page-Size", "Letter"); request.Headers.Add("X-Page-Layout:1x2"); // layout labels with 1 column and 3 rows (3 labels per page) var requestStream = request.GetRequestStream(); requestStream.Write(zplByte, 0, zplByte.Length); requestStream.Close(); try { //get the response from the request var response = (HttpWebResponse)request.GetResponse(); //get the response stream var responseStream = response.GetResponseStream(); //create file where response data will go var fileStream = File.Create(filePath); //convert the responseStream to a file at specified path responseStream.CopyTo(fileStream); //close the stream responseStream.Close(); fileStream.Close(); //inform of success //Console.WriteLine("Successfully retrieved the PDF for the ZPL string!"); } catch (WebException e) { //Console.WriteLine("ERROR: {0}\n", e.Message); } }
public async Task UpdateCompanyAddressInvalidTests() { //Act - firstly get the user object as we need the user's ID var user = await new UserServices().GetUserDetails(CompanyAdminPageModelServiceTests.UserEmail, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsNotNull(user); Assert.AreEqual(UserEmail, user.Email); //Arrange int userId = user.Id; string encodedId = userId.ToString().Base64Encode(); CompanyAddressModel address = new CompanyAddressModel { Id = 0, CompanyId = user.CompanyId, Postcode = "NN15 6XU", AddressLine1 = "Unit Test House OscarWeb", AddressLine2 = "Kettering Business Venture Park", AddressLine3 = "Kettering", AddressLine4 = "Northants", AddressLine5 = "", Primary = false, Active = true }; var service = new CompanyAdminPageModelService(); //Act var response = await service.UpdateCompanyAddress(null, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsFalse(response); address.Postcode = ""; //Act response = await service.UpdateCompanyAddress(address, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsFalse(response); address.Postcode = "NN15 6XU"; address.AddressLine1 = ""; //Act response = await service.UpdateCompanyAddress(address, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsFalse(response); address.Postcode = "NN15 6XU"; address.AddressLine1 = "Unit Test House OscarWeb"; response = await service.UpdateCompanyAddress(address, null, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsFalse(response); response = await service.UpdateCompanyAddress(address, "", CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsFalse(response); }
public async Task InsertUpdateGetDeleteCompanyAddressTests() { //Act - firstly get the user object as we need the user's ID var user = await new UserServices().GetUserDetails(CompanyAdminPageModelServiceTests.UserEmail, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsNotNull(user); Assert.AreEqual(UserEmail, user.Email); //Arrange int userId = user.Id; string encodedId = userId.ToString().Base64Encode(); CompanyAddressModel address = new CompanyAddressModel { Id = 0, CompanyId = user.CompanyId, Postcode = "NN15 6XU", AddressLine1 = "Unit Test House OscarWeb", AddressLine2 = "Kettering Business Venture Park", AddressLine3 = "Kettering", AddressLine4 = "Northants", AddressLine5 = "", Primary = false, Active = true }; //Act - create the company address var response = await new CompanyAdminPageModelService().CreateCompanyAddress(address, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsTrue(response); var addresses = await new CompanyAdminPageModelService().GetCompanyAddresses(user.Email, CompanyAdminPageModelServiceTests.Rooturl, encodedId, user.CompanyId, true); //Assert Assert.IsNotNull(addresses); Assert.IsNotNull(addresses.Addresses); Assert.IsTrue(addresses.Addresses.Any()); //find the newly added company address var foundAddress = addresses.Addresses.Find(c => c.AddressLine1 == "Unit Test House OscarWeb"); //Assert Assert.IsNotNull(foundAddress); Assert.IsTrue(foundAddress.Id > 0); Assert.AreEqual(address.AddressLine1, foundAddress.AddressLine1); //Arrange int identifier = foundAddress.Id; address.Id = identifier; address.AddressLine1 = $"{address.AddressLine1}_updated"; //Act - update the company address response = await new CompanyAdminPageModelService().UpdateCompanyAddress(address, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsTrue(response); addresses = await new CompanyAdminPageModelService().GetCompanyAddresses(user.Email, CompanyAdminPageModelServiceTests.Rooturl, encodedId, user.CompanyId, true); //Assert Assert.IsNotNull(addresses); Assert.IsNotNull(addresses.Addresses); Assert.IsTrue(addresses.Addresses.Any()); //find the updated company address foundAddress = addresses.Addresses.Find(c => c.AddressLine1 == "Unit Test House OscarWeb_updated"); //Assert Assert.IsNotNull(foundAddress); Assert.IsTrue(foundAddress.Id > 0); Assert.AreEqual(address.AddressLine1, foundAddress.AddressLine1); //Arrange response = await new CompanyAdminPageModelService().DeleteCompanyAddress(identifier, encodedId, CompanyAdminPageModelServiceTests.Rooturl); //Assert Assert.IsTrue(response); }