public void SaveControl() { Inventory itemToSave = new Inventory(); if (EditOption) { itemToSave = InventoryManager.Load(InventoryId); } itemToSave.Color = txtColor.Text; itemToSave.Price = (decimal)txtprice.Value; itemToSave.Quantity = (int)txtqty.Value; itemToSave.Year = (int)txtyear.Value; int modelId = 0; int.TryParse(ddlCarModel.SelectedValue, out modelId); itemToSave.ModelId = modelId; int locationId = 0; int.TryParse(ddlLocation.SelectedValue, out locationId); itemToSave.LocationId = locationId; string errorMessage; InventoryManager.Save(itemToSave, out errorMessage); }
/// <summary> /// Saves a Inventory to the data store. /// </summary> /// <param name="item">The item to save</param> public static void Save(Inventory item) { if (item.IsItemModified) { if (item.InventoryId == null) { item.InventoryId = Insert(item); } else { Update(item); } } }
public static Special CreateSpecialObject(Inventory inventory) { Random rand = new Random(); Special special = new Special { DateEnd = DateTime.Parse("4/1/2013"), DateStart = DateTime.Parse("1/1/2013"), IsItemModified = true, InventoryId = inventory.InventoryId.GetValueOrDefault(), SpecialId = null, Price = (decimal)((rand.NextDouble() + .01) * rand.Next(5, 100)) }; string errorMessage; SpecialManager.Save(special, out errorMessage); return special; }
/// <summary> /// Updates a Inventory /// </summary> /// <param name="item">The Inventory item to save</param> private static void Update(Inventory item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@InventoryId", item.InventoryId), new SqlParameter("@ModelId", item.ModelId), new SqlParameter("@Year", item.Year), new SqlParameter("@Quantity", item.Quantity), new SqlParameter("@LocationId", item.LocationId), new SqlParameter("@Color", item.Color), new SqlParameter("@Price", item.Price), new SqlParameter("@Deleted", item.Deleted) }; DataManager.ExecuteProcedure(KarzPlusConnectionString, "PKP_UpdateInventory", parameters); }
/// <summary> /// Inserts a new Inventory /// </summary> /// <param name="item">The Inventory item to insert</param> /// <returns>The id of the Inventory item just inserted</returns> private static int Insert(Inventory item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@ModelId", item.ModelId), new SqlParameter("@Year", item.Year), new SqlParameter("@Quantity", item.Quantity), new SqlParameter("@LocationId", item.LocationId), new SqlParameter("@Color", item.Color), new SqlParameter("@Price", item.Price), new SqlParameter("@Deleted", item.Deleted) }; return Convert.ToInt32(DataManager.ExecuteScalarProcedure(KarzPlusConnectionString, "PKP_InsertInventory", parameters)); }
public void CreateTestObject() { int inventoryId; Guid userId = Guid.Empty; Random rand = new Random(); string errorMessage; string userName = string.Format("NewUser_{0}", rand.Next(1, 100000)); const string passWord = "******"; string email = string.Format("emailaddress{0}@test.com", rand.Next(1, 1000000000)); MembershipCreateStatus status; MembershipUser user = Membership.CreateUser(userName, passWord, email, "quieres apple?", "no, apple es para mujeres", true, out status); if (user != null && user.ProviderUserKey is Guid) { userId = (Guid)user.ProviderUserKey; } List<Inventory> inventoryList = InventoryManager.LoadAll().ToList(); if (inventoryList.SafeAny()) { inventoryId = inventoryList.First().InventoryId.GetValueOrDefault(); } else { CarMake newMake = new CarMake { Manufacturer = "TestManufacturer", Name = string.Format("Make_{0}", rand.Next(1, 1000)) }; CarMakeManager.Save(newMake, out errorMessage); CarModel newModel = new CarModel { MakeId = newMake.MakeId.GetValueOrDefault(), Name = string.Format("Model_{0}", rand.Next(1, 1000)) }; CarModelManager.Save(newModel, out errorMessage); Location location = new Location { Name = string.Format("Location_{0}", rand.Next(1, 100000)), Address = string.Format("{0} Street St", rand.Next(10, 1000)), City = "Fake City", State = "FS", Zip = "11111", Email = "*****@*****.**", Phone = "1112223333" }; LocationManager.Save(location, out errorMessage); Inventory inventory = new Inventory { ModelId = newModel.ModelId.GetValueOrDefault(), LocationId = location.LocationId.GetValueOrDefault(), Color = "Red", Price = (decimal) ((rand.NextDouble() + 0.1)*rand.Next(10, 60)), Quantity = rand.Next(1, 10), Year = rand.Next(1990, 2015) }; inventoryId = inventory.InventoryId.GetValueOrDefault(); } TransactionTestObject = new Transaction { BillingAddress = "123 Fake Street", BillingCity = "Fake City", BillingState = "FS", BillingZip = "12345", CCV = 123, CreditCardNumber = "4444999911110000", ExpirationDate = DateTime.Today.AddYears(rand.Next(5, 10)), InventoryId = inventoryId, Price = (decimal)( ( rand.NextDouble() + 0.1 ) * rand.Next(10, 60) ), RentalDateEnd = DateTime.Today.AddDays(rand.Next(11, 50)), RentalDateStart = DateTime.Today.AddDays(rand.Next(1, 10)), TransactionDate = DateTime.Today, UserId = userId }; TransactionManager.Save(TransactionTestObject, out errorMessage); }
public static Inventory CreateTestObject() { int carModelId = default(int), locationId = default(int); string errorMessage; Random rand = new Random(); List<CarModel> carModels = CarModelManager.LoadAll().ToList(); if (carModels.SafeAny()) { carModelId = carModels.First().ModelId.GetValueOrDefault(); } else { CarModel carModel = new CarModel { Name = string.Format("TestCarModel_{0}", rand.Next(1, 1000)) }; CarModelManager.Save(carModel, out errorMessage); if (carModel.ModelId.HasValue) { carModelId = carModel.ModelId.Value; } } List<Location> locations = LocationManager.LoadAll().ToList(); if (locations.SafeAny()) { locationId = locations.First(l => l.LocationId.HasValue).LocationId.GetValueOrDefault(); } else { Location location = new Location { Name = string.Format("TestLocation_{0}", rand.Next(1, 1000)), Address = "123 Fake Street", City = "Fake City", Email = "*****@*****.**", Phone = "5555555555", State = "FS", Zip = "55555" }; LocationManager.Save(location, out errorMessage); if (location.LocationId.HasValue) { locationId = location.LocationId.Value; } } Inventory inventory = new Inventory { ModelId = carModelId, Color = "Black", Price = (decimal)((rand.NextDouble() + .01) * rand.Next(5, 100)), LocationId = locationId, Quantity = rand.Next(1, 50), Year = rand.Next(DateTime.Now.AddYears(rand.Next(1, 100).NegativeValue()).Year, DateTime.Now.Year) }; InventoryManager.Save(inventory, out errorMessage); return inventory; }
public void TestInitialize() { InventoryTestObject = CreateTestObject(); }
public static void DeleteInventoryObject(Inventory inventory) { if (inventory != null && inventory.InventoryId.HasValue) { InventoryManager.HardDelete(inventory.InventoryId.Value); } }
/// <summary> /// Validate Inventory Entity /// </summary> /// <param name="item">Entity to validate</param> /// <param name="errorMessage">error message if validation failed</param> /// <returns>return true if entity passes validation logic, else return false</returns> public static bool Validate(Inventory item, out string errorMessage) { errorMessage = string.Empty; CarModel carModel = CarModelManager.Load(item.ModelId); if (carModel == null) { errorMessage += "ModelId must be valid. "; } Location location = LocationManager.Load(item.LocationId); if (location == null) { errorMessage += "LocationId must be valid. "; } errorMessage = errorMessage.TrimSafely(); return errorMessage.IsNullOrWhiteSpace(); }
/// <summary> /// Save Inventory Entity /// </summary> /// <param name="item">Entity to save</param> /// <param name="errorMessage">Error Message</param> /// <returns>return true if save successfully, else return false</returns> public static bool Save(Inventory item, out string errorMessage) { bool isValid = Validate(item, out errorMessage); if (isValid) { InventoryDao.Save(item); } return isValid; }