public static void SaveListing(int listingId, int modelId, int bodyStyleid, int interiorColorid, int exteriorColorid, Condition condition, Transmission transmission, int mileage, int modelYear, string VIN, decimal MSRP, decimal salePrice, string vdesc, string imageFileUrl, bool isFeatured, bool isSold, int month, int day, int year, bool expected) { DateTime DateAdded = new DateTime(year, month, day); ListingManager manager = new ListingManager(new ListingMemRepo_GOODDATA()); Listing listing = new Listing { ListingId = listingId, ModelId = modelId, BodyStyleId = bodyStyleid, InteriorColorId = interiorColorid, ExteriorColorId = exteriorColorid, Condition = condition, Transmission = transmission, Mileage = mileage, ModelYear = modelYear, VIN = VIN, MSRP = MSRP, SalePrice = salePrice, VehicleDescription = vdesc, ImageFileUrl = imageFileUrl, IsFeatured = isFeatured, IsSold = isSold, DateAdded = DateAdded, }; var test = manager.SaveListing(listing); Assert.AreEqual(expected, test.Success); }
public CompanyStoreDataSeederContributor(IRepository <Company, Guid> companiesRepository, IListingRepository authorRepository, ListingManager authorManager) { _companiesRepository = companiesRepository; _authorRepository = authorRepository; _authorManager = authorManager; }
public IHttpActionResult Search(string view, string quickSearch, int?minPrice, int?maxPrice, int?minYear, int?maxYear) { //check model state befor try _listingManager = ListingManagerFactory.Create(); try { var parameters = new ListingSearchParameters() { View = view, QuickSearch = quickSearch, MinPrice = minPrice, MaxPrice = maxPrice, MinYear = minYear, MaxYear = maxYear }; var result = _listingManager.Search(parameters); return(Ok(result.Payload)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void GenerateUnitTests_TestsGenerated() { string chapter = "Chapter01"; ICollection <string> filesToCreate = new List <string> { @"Chapter01\Listing01.01.Something.cs", @"Chapter01\Listing01.02A.cs", @"Chapter01\Listing01.03B.Other.cs" }; var expectedFilesList = new List <string>(); foreach (string file in filesToCreate) { expectedFilesList.Add(file.Replace(chapter, chapter + ".Tests")); } var expectedFiles = (ICollection <string>)expectedFilesList; expectedFiles = ConvertFilenamesToFullPath(expectedFiles); WriteFiles(filesToCreate); CreatedDirectories.Add(chapter); CreatedDirectories.Add(chapter + ".Tests"); var generatedTests = ListingManager.GenerateUnitTests( Path.Combine(Environment.CurrentDirectory, "Chapter01")); CollectionAssert.AreEquivalent((ICollection)expectedFiles, (ICollection)generatedTests); }
public ActionResult Index() { //get managers ListingManager listingManager = ListingManagerFactory.Create(); SpecialManager specialManager = SpecialManagerFactory.Create(); //get responses ListingFeaturedResponse listingFeaturedResponse = listingManager.GetFeaturedListings(); SpecialGetAllResponse specialResponse = specialManager.GetAllSpecials(); //validate responses if (!listingFeaturedResponse.Success || !specialResponse.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{listingFeaturedResponse.Message} {specialResponse.Message}")); } else { //build vm HomeVM model = new HomeVM(); model.SetFeaturedListingItems(listingFeaturedResponse.Listings); model.SetSpecialItems(specialResponse.Specials); return(View(model)); } }
public IActionResult Index() { ListingManager lm = new ListingManager(_connectionString); List <Item> items = lm.GetAllItems().OrderByDescending(d => d.Date).ToList(); if (HttpContext.Session.Get("List") != null) { string session = HttpContext.Session.Get("List").ToString(); List <string> SessionList = session.Split(',').ToList(); ListItemAndString l = new ListItemAndString { items = items, Session = SessionList }; return(View(l)); } else { ListItemAndString l = new ListItemAndString { items = items, Session = null }; return(View(l)); } }
private void UploadImages() { new System.Threading.Thread(() => { Console.WriteLine("Intro========== " + imageCaptions.Count); FtpManager ftpManger = new FtpManager(); ListingManager listingManager = new ListingManager(); ftpManger.OnProgressChange += ftpManger_OnProgressChange; Hashing hashing = new Hashing(); List <string> urls = new List <string>(); List <string> links = new List <string>(); numberOfImages = localFilePaths.Count(); foreach (string localFile in localFilePaths) { numberToUpload++; string fileHash = hashing.HashFile(localFile); string extension = System.IO.Path.GetExtension(localFile); urls.Add(webDir + fileHash + extension); links.Add(linkDir + fileHash + extension); } for (int i = 0; i < numberOfImages; i++) { LoadImage(localFilePaths[i]); Console.WriteLine("Pregame========== " + imageCaptions.Count); UpdateProgress(numberToUpload, i + 1); ftpManger.UploadFile(localFilePaths[i], urls[i]); listingManager.AddListingImage(propertyID, links[i], imageCaptions[i]); } CloseForm(); }).Start(); }
private void UploadImages() { List <int> delImage = new List <int>(); ListingManager listManager = new ListingManager(); for (int i = 0; i < imageSource.Count; i++) { if (imageSource[i] == " " || imageSource[i] == "") { delImage.Add(i); listManager.EditListingImage(imageID[i], imageCaptions[i]); } } for (int i = delImage.Count - 1; i >= 0; i--) { if (delImage.IndexOf(i) != -1) { imageSource.RemoveAt(i); imageCaptions.RemoveAt(i); } } for (int i = 0; i < imageSource.Count; i++) { Console.WriteLine(i + " New " + imageID[i] + " - " + imageSource[i] + " with " + imageCaptions[i] + " of " + imageSource.Count); } Overlays.Listings.LoadingOverlay uploadImages = new Overlays.Listings.LoadingOverlay(propertyID, imageSource, imageCaptions); uploadImages.Owner = Framework.UI.Controls.Window.GetWindow(this); uploadImages.Show(); (this.Tag as AgentWindow).HideEditListingView(); (this.Tag as AgentWindow).ShowListingsView(); ClearView(); }
public void UpdateOnlyChapterNumberOfListingUsingChapterNumberFromFolder_UnitTestsAlsoUpdated_ListingsAndTestsUpdated() { ICollection <string> filesToMake = new List <string> { "Chapter42/Listing01.01.cs", "Chapter42/Listing01.01A.Some.cs", "Chapter42/Listing01.01B.cs", "Chapter42/Listing01.01C.cs", "Chapter42/Listing01.05.cs", "Chapter42.Tests/Listing01.01.cs", "Chapter42.Tests/Listing01.01A.Some.cs", "Chapter42.Tests/Listing01.01B.cs", "Chapter42.Tests/Listing01.01C.cs", "Chapter42.Tests/Listing01.05.cs" }; ICollection <string> expectedFiles = new List <string> { @"Chapter42\Listing42.01.cs", @"Chapter42\Listing42.01A.Some.cs", @"Chapter42\Listing42.01B.cs", @"Chapter42\Listing42.01C.cs", @"Chapter42\Listing42.05.cs", @"Chapter42.Tests\Listing42.01.cs", @"Chapter42.Tests\Listing42.01A.Some.cs", @"Chapter42.Tests\Listing42.01B.cs", @"Chapter42.Tests\Listing42.01C.cs", @"Chapter42.Tests\Listing42.05.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); CreatedDirectories.Add("Chapter42"); CreatedDirectories.Add("Chapter42.Tests"); ListingManager.UpdateChapterListingNumbers(Path.Combine(Environment.CurrentDirectory, "Chapter42"), byFolder: true, chapterOnly: true); var files = FileManager.GetAllFilesAtPath(Environment.CurrentDirectory, true) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); //Assert CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
public ActionResult Purchase(PurchaseListingVM model) { _purchaseManager = PurchaseManagerFactory.Create(); _stateManager = StateManagerFactory.Create(); _listingManager = ListingManagerFactory.Create(); try { var listingResponse = _listingManager.GetListingById(model.ListingToPurchase.ListingId); model.ListingToPurchase = listingResponse.Payload; if (ModelState.IsValid) { //set sold listing in db //set user name model.PurchaseForm.UserName = User.Identity.Name; //set listing id model.PurchaseForm.ListingId = model.ListingToPurchase.ListingId; //set date model.PurchaseForm.DateAdded = DateTime.Now; //send to manager var response = _purchaseManager.SavePurchase(model.PurchaseForm); if (!response.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}")); } } else { var stateResponse = _stateManager.GetAllStates(); model.States = stateResponse.Payload.Select(m => new SelectListItem { Text = m.StateAbbreviation, Value = m.StateId.ToString() }); return(View(model)); } return(RedirectToAction("Index")); } catch (Exception ex) { throw new ApplicationException("Something wrong happened while loading a purchase:", ex); } }
public void GetPathToAccompanyingUnitTest_GivenListingWithNoTest_CorrectPathReturned(string chapter, string listingName) { bool result = ListingManager.GetPathToAccompanyingUnitTest(chapter + Path.DirectorySeparatorChar + listingName, out string pathToTest); char directorySeperator = Path.DirectorySeparatorChar; Assert.IsFalse(result); Assert.AreEqual($"{chapter}.Tests{directorySeperator}{listingName}", pathToTest); }
public IHttpActionResult GetUsedInventoryReport(string report) { _listingManager = ListingManagerFactory.Create(); try { var result = _listingManager.GetInventoryReport(report); return(Ok(result.Payload)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult DeleteListing(int listingId) { _listingManager = ListingManagerFactory.Create(); var response = _listingManager.DeleteListing(listingId); if (response.Success) { return(RedirectToAction("Vehicles")); } else { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}")); } }
public void UpdateChapterListingNumbers_AdditionalListings_ListingsRenumbered() { ICollection <string> filesToMake = new List <string> { "Listing01.01.cs", "Listing01.01A.Some.cs", "Listing01.01B.cs", "Listing01.01C.cs", "Listing01.02.cs", "Listing01.02A.Test.cs" }; ICollection <string> expectedFiles = new List <string> { "Listing01.01.cs", "Listing01.02.Some.cs", "Listing01.03.cs", "Listing01.04.cs", "Listing01.05.cs", "Listing01.06.Test.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); ListingManager.UpdateChapterListingNumbers(Environment.CurrentDirectory); var files = Directory.EnumerateFiles(Environment.CurrentDirectory) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
public void IsIncorrectListingFromPath_FindsIncorrectListing(string fileName, bool expectedResult) { WriteFile(fileName); string directoryName = Path.GetDirectoryName(fileName); if (!string.IsNullOrWhiteSpace(directoryName)) { CreatedDirectories.Add(directoryName); } string path = Path.Combine(Environment.CurrentDirectory, fileName); bool actualResult = ListingManager.IsExtraListing(path); Assert.AreEqual(expectedResult, actualResult); }
public ActionResult Details(int id) { _listingManager = ListingManagerFactory.Create(); var response = _listingManager.GetListingById(id); if (!response.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}")); } else { var model = new ListingVM(); model.Listing = response.Payload; return(View(model)); } }
public static void CanGetListingByIdALWAYSNULL(int listingId, bool expected) { ListingManager manager = new ListingManager(new ListingMemRepo_ALWAYSNULL()); var test = manager.GetListingById(listingId); bool actual; if (test.Payload == null) { actual = false; } else { actual = true; } Assert.AreEqual(expected, actual); }
public IActionResult SubmitItem(Item I) { ListingManager lm = new ListingManager(_connectionString); int Id = lm.AddItem(I); string Idstring = Id.ToString(); Idstring += ","; if (HttpContext.Session.Get("List") == null) { HttpContext.Session.Set("List", Idstring); } else { string ItemIds = HttpContext.Session.Get("List").ToString(); List <string> ids = ItemIds.Split(',').ToList(); ids.Add(Idstring); HttpContext.Session.Set("List", ids); } return(Redirect("/Home/Index")); }
public ActionResult Purchase(int id) { try { _listingManager = ListingManagerFactory.Create(); _stateManager = StateManagerFactory.Create(); var listingResponse = _listingManager.GetListingById(id); if (!listingResponse.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{listingResponse.Message}")); } else { var model = new PurchaseListingVM { ListingToPurchase = listingResponse.Payload, PurchaseForm = new Purchase() }; var stateResponse = _stateManager.GetAllStates(); model.States = stateResponse.Payload.Select(m => new SelectListItem { Text = m.StateAbbreviation, Value = m.StateId.ToString() }); return(View(model)); } } catch (Exception ex) { throw new ApplicationException("Something wrong happened while loading a purchase:", ex); } }
public void GetAllExtraListings_ExtraListingsReturned() { ICollection <string> filesToMake = new List <string> { @"Chapter01\Listing01.01A.SpecifyingLiteralValues.cs", @"Chapter02\Listing02.01B.Something.cs", @"Chapter02\Listing02.02.cs", @"Chapter02\Listing02.03C.cs" }; CreatedDirectories.Add("Chapter01"); CreatedDirectories.Add("Chapter02"); ICollection <string> expectedFiles = filesToMake; expectedFiles.Remove(@"Chapter02\Listing02.02.cs"); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); WriteFiles(filesToMake); var extraListings = ListingManager.GetAllExtraListings(Environment.CurrentDirectory).ToList(); CollectionAssert.AreEquivalent((ICollection)expectedFiles, (ICollection)extraListings); }
public void UpdateChapterListingNumbers_MultipleListingsMissing_ListingsRenumbered() { ICollection <string> filesToMake = new List <string> { "Listing09.01.DeclaringAStruct.cs", "Listing09.02.ErroneousInitialization.cs", "Listing09.03.AccessError.cs", "Listing09.05.SubtleBoxAndUnboxInstructions.cs", "Listing09.06.UnboxMustBeSameType.cs", "Listing09.07.SubtleBoxingIdiosyncrasies.cs", "Listing09.08.AvoidingUnboxingAndCopying.cs", "Listing09.09.ComparingAnIntegerSwitchToAnEnumSwitch.cs", "Listing09.10.DefiningAnEnum.cs", "Listing09.11.DefiningAnEnumType.cs", "Listing09.12.CastingBetweenArraysOfEnums.cs", "Listing09.13.ConvertingAStringToAnEnumUsingEnum.Parse.cs", "Listing09.14.ConvertingAStringToAnEnumUsingEnum.TryParse.cs", "Listing09.15.UsingEnumsAsFlags.cs", "Listing09.16.UsingBitwiseORandANDWithFlagEnums.cs", "Listing09.17.DefiningEnumValuesforFrequentCombinations.cs", "Listing09.18.UsingFlagsAttribute.cs" }; ICollection <string> expectedFiles = new List <string> { "Listing09.01.DeclaringAStruct.cs", "Listing09.02.ErroneousInitialization.cs", "Listing09.03.AccessError.cs", "Listing09.04.SubtleBoxAndUnboxInstructions.cs", "Listing09.05.UnboxMustBeSameType.cs", "Listing09.06.SubtleBoxingIdiosyncrasies.cs", "Listing09.07.AvoidingUnboxingAndCopying.cs", "Listing09.08.ComparingAnIntegerSwitchToAnEnumSwitch.cs", "Listing09.09.DefiningAnEnum.cs", "Listing09.10.DefiningAnEnumType.cs", "Listing09.11.CastingBetweenArraysOfEnums.cs", "Listing09.12.ConvertingAStringToAnEnumUsingEnum.Parse.cs", "Listing09.13.ConvertingAStringToAnEnumUsingEnum.TryParse.cs", "Listing09.14.UsingEnumsAsFlags.cs", "Listing09.15.UsingBitwiseORandANDWithFlagEnums.cs", "Listing09.16.DefiningEnumValuesforFrequentCombinations.cs", "Listing09.17.UsingFlagsAttribute.cs" }; IEnumerable <string> toWrite = new List <string> { "namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_01", "{", " using System;", " using System.Reflection;", " public class Program { }", "}" }; WriteFiles(filesToMake, toWrite); expectedFiles = ConvertFilenamesToFullPath(expectedFiles); foreach (string file in filesToMake) { CreatedFiles.Remove(file); } CreatedFiles.AddRange(expectedFiles); ListingManager.UpdateChapterListingNumbers(Environment.CurrentDirectory); var files = Directory.EnumerateFiles(Environment.CurrentDirectory) .Where(x => Path.GetExtension(x) == ".cs").OrderBy(x => x).ToList(); CollectionAssert.AreEquivalent((ICollection)expectedFiles, files); }
public ActionResult EditVehicle(EditListingVM model) { if (ModelState.IsValid) { try { _listingManager = ListingManagerFactory.Create(); var oldListingResponse = _listingManager.GetListingById(model.Listing.ListingId); if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { var savepath = Server.MapPath("~/Images/"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.Listing.ImageFileUrl = Path.GetFileName(filePath); //delete the old file, use the response to get it var oldPath = Path.Combine(savepath, oldListingResponse.Payload.ImageFileUrl); if (System.IO.File.Exists(oldPath)) { System.IO.File.Delete(oldPath); } } else { model.Listing.ImageFileUrl = oldListingResponse.Payload.ImageFileUrl; } var listingResponse = _listingManager.UpdateListing(model.Listing); if (listingResponse.Success) { return(RedirectToAction("Vehicles")); //return RedirectToAction("EditVehicle", new { id = listingResponse.Payload.ListingId }); } else { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" + $"{listingResponse.Message}")); } } catch (Exception ex) { throw new ApplicationException("Something wrong happened while trying to edit a listing:", ex); } } else { //reset page with items _makeManager = MakeManagerFactory.Create(); _modelManager = ModelManagerFactory.Create(); _interiorColorManager = InteriorColorManagerFactory.Create(); _exteriorColorManager = ExteriorColorManagerFactory.Create(); _bodyStyleManager = BodyStyleManagerFactory.Create(); _listingManager = ListingManagerFactory.Create(); //load all the items var modelResponse = _modelManager.GetAllModels(); var makeResponse = _makeManager.GetAllMakes(); var interiorResponse = _interiorColorManager.GetAll(); var exteriorReponse = _exteriorColorManager.GetAll(); var bodyResponse = _bodyStyleManager.GetAll(); //verify they all loaded if (!modelResponse.Success || !makeResponse.Success || !interiorResponse.Success || !exteriorReponse.Success || !bodyResponse.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" + $"{modelResponse.Message} " + $"{makeResponse.Message}" + $"{interiorResponse.Message}" + $"{exteriorReponse.Message}" + $"{bodyResponse.Message}")); } else { //create select list items model.Makes = makeResponse.Payload.Select(m => new SelectListItem { Text = m.MakeName, Value = m.MakeId.ToString() }); model.Models = modelResponse.Payload.Select(m => new SelectListItem { Text = m.ModelName, Value = m.ModelId.ToString() }); model.ExteriorColors = exteriorReponse.Payload.Select(m => new SelectListItem { Text = m.ExteriorColorName, Value = m.ExteriorColorId.ToString() }); model.InteriorColors = interiorResponse.Payload.Select(m => new SelectListItem { Text = m.InteriorColorName, Value = m.InteriorColorId.ToString() }); model.BodyStyles = bodyResponse.Payload.Select(m => new SelectListItem { Text = m.BodyStyleName, Value = m.BodyStyleId.ToString() }); return(View(model)); } } }
public ActionResult EditVehicle(int id) { var model = new EditListingVM(); //reset page with items _makeManager = MakeManagerFactory.Create(); _modelManager = ModelManagerFactory.Create(); _interiorColorManager = InteriorColorManagerFactory.Create(); _exteriorColorManager = ExteriorColorManagerFactory.Create(); _bodyStyleManager = BodyStyleManagerFactory.Create(); _listingManager = ListingManagerFactory.Create(); //load all the items var modelResponse = _modelManager.GetAllModels(); var makeResponse = _makeManager.GetAllMakes(); var interiorResponse = _interiorColorManager.GetAll(); var exteriorReponse = _exteriorColorManager.GetAll(); var bodyResponse = _bodyStyleManager.GetAll(); //get listing var listingResponse = _listingManager.GetListingById(id); //verify they all loaded if (!modelResponse.Success || !makeResponse.Success || !interiorResponse.Success || !exteriorReponse.Success || !bodyResponse.Success || !listingResponse.Success) { return(new HttpStatusCodeResult(500, $"Error in cloud. Message:" + $"{modelResponse.Message} " + $"{makeResponse.Message}" + $"{interiorResponse.Message}" + $"{exteriorReponse.Message}" + $"{bodyResponse.Message}" + $"{listingResponse.Message}")); } else { //create select list items model.Makes = makeResponse.Payload.Select(m => new SelectListItem { Text = m.MakeName, Value = m.MakeId.ToString() }); model.Models = modelResponse.Payload.Select(m => new SelectListItem { Text = m.ModelName, Value = m.ModelId.ToString() }); model.ExteriorColors = exteriorReponse.Payload.Select(m => new SelectListItem { Text = m.ExteriorColorName, Value = m.ExteriorColorId.ToString() }); model.InteriorColors = interiorResponse.Payload.Select(m => new SelectListItem { Text = m.InteriorColorName, Value = m.InteriorColorId.ToString() }); model.BodyStyles = bodyResponse.Payload.Select(m => new SelectListItem { Text = m.BodyStyleName, Value = m.BodyStyleId.ToString() }); model.Listing = listingResponse.Payload; return(View(model)); } }
private void BT_DeleteListing_Click(object sender, RoutedEventArgs e) { ListingManager listMan = new ListingManager(); listMan.DeleteListing(selectedListingID); }