예제 #1
0
 /// <summary>
 /// Saves a Location to the data store.
 /// </summary>
 /// <param name="item">The item to save</param>
 public static void Save(Location item)
 {
     if (item.IsItemModified)
     {
         if (item.LocationId == null)
         {
             item.LocationId = Insert(item);
         }
         else
         {
             Update(item);
         }
     }
 }
예제 #2
0
        public void CreateTestObject()
        {
            Random rand = new Random();
            LocationTestObject
                = new Location
                {
                    Name = string.Format("TestLocation_{0}", rand.Next(1, 1000)),
                    Address = "123 Fake Street",
                    City = "Fake City",
                    Email = "*****@*****.**",
                    Phone = "5551112234",
                    State = "FS",
                    Zip = "11233"
                };

            string errorMessage;
            LocationManager.Save(LocationTestObject, out errorMessage);
        }
        public bool SaveControl()
        {
            bool valid = false;
            lblError.Text = string.Empty;
            Location location = new Location();
            if (EditOption)
            {
                location = LocationManager.Load(LocationId);
            }

            location.Name = txtLocationName.Text;
            location.Address = txtAddress.Text;
            location.City = txtCity.Text;
            location.Zip = txtZip.Text;
            location.Phone = txtPhone.Text;
            location.Email = txtEmail.Text;
            location.State = ddlLocation.SelectedValue;

            string errorMessage;
            valid = LocationManager.Save(location, out errorMessage);
            lblError.Text = errorMessage;
            return valid;
        }
        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);
        }
예제 #5
0
        /// <summary>
        /// Save Location 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(Location item, out string errorMessage)
        {
            bool isValid = Validate(item, out errorMessage);

            if (isValid)
            {
                LocationDao.Save(item);
            }

            return isValid;
        }
예제 #6
0
        /// <summary>
        /// Validate Location 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(Location item, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (item.Name.IsNullOrWhiteSpace())
            {
                errorMessage += "Name is required. ";
            }

            if (item.Address.IsNullOrWhiteSpace())
            {
                errorMessage += "Address is required. ";
            }

            if (item.City.IsNullOrWhiteSpace())
            {
                errorMessage += "City is required. ";
            }

            if (item.State.IsNullOrWhiteSpace())
            {
                errorMessage += "State is required. ";
            }

            if (item.Zip.IsNullOrWhiteSpace())
            {
                errorMessage += "Zip is required. ";
            }

            if (item.Phone.HasValue() && !item.Phone.IsPhone())
            {
                errorMessage += "Phone must be valid. ";
            }

            if (item.Email.HasValue() && !item.Email.IsEmail())
            {
                errorMessage += "Email must be valid. ";
            }

            errorMessage = errorMessage.TrimSafely();

            return errorMessage.IsNullOrWhiteSpace();
        }
예제 #7
0
        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;
        }
예제 #8
0
 /// <summary>
 /// Updates a Location
 /// </summary>
 /// <param name="item">The Location item to save</param>
 private static void Update(Location item)
 {
     List<SqlParameter> parameters
         = new List<SqlParameter>
             {
                 new SqlParameter("@LocationId", item.LocationId),
                 new SqlParameter("@Name", item.Name),
                 new SqlParameter("@Address", item.Address),
                 new SqlParameter("@City", item.City),
                 new SqlParameter("@State", item.State),
                 new SqlParameter("@Zip", item.Zip),
                 new SqlParameter("@Phone", item.Phone),
                 new SqlParameter("@Email", item.Email),
                 new SqlParameter("@Deleted", item.Deleted)
             };
     DataManager.ExecuteProcedure(KarzPlusConnectionString, "PKP_UpdateLocation", parameters);
 }
예제 #9
0
 /// <summary>
 /// Inserts a new Location
 /// </summary>
 /// <param name="item">The Location item to insert</param>
 /// <returns>The id of the Location item just inserted</returns>
 private static int Insert(Location item)
 {
     List<SqlParameter> parameters
         = new List<SqlParameter>
             {
                 new SqlParameter("@Name", item.Name),
                 new SqlParameter("@Address", item.Address),
                 new SqlParameter("@City", item.City),
                 new SqlParameter("@State", item.State),
                 new SqlParameter("@Zip", item.Zip),
                 new SqlParameter("@Phone", item.Phone),
                 new SqlParameter("@Email", item.Email),
                 new SqlParameter("@Deleted", item.Deleted)
             };
     return Convert.ToInt32(DataManager.ExecuteScalarProcedure(KarzPlusConnectionString, "PKP_InsertLocation", parameters));
 }