Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync(string streetAddress1 = "", string streetAddress2 = "", string city = "",
                                                      string state          = "", string zip = "")
        {
            if (Agency.AddressID <= 0)
            {
                //If no addressID has been selected check if all "New Address" fields have values
                if (string.IsNullOrEmpty(streetAddress1) || string.IsNullOrEmpty(city) || string.IsNullOrEmpty(state) || string.IsNullOrEmpty(zip))
                {
                    ModelState.AddModelError(nameof(Agency.AgencyID), "Please select an existing address or fill out Street Address 1," +
                                             " City, State, and Zip for a new address.");
                }
                else
                {
                    //Remove AddressID from validation when all new address fields have been entered
                    ModelState.Remove("Agency.AddressID");
                }
            }
            if (!ModelState.IsValid)
            {
                Addresses = _context.Addresses.ToList();
                return(Page());
            }
            //Create New Address if Needed
            if (Agency.AddressID <= 0)
            {
                Address address = new Address
                {
                    StreetAddress1 = streetAddress1,
                    StreetAddress2 = streetAddress2 == null ? "" : streetAddress2,
                    CityName       = city,
                    StateShortName = state,
                    Zipcode        = zip
                };

                _context.Addresses.Add(address);
                await _context.SaveChangesAsync();

                Agency.AddressID = address.AddressID;
            }

            _context.Attach(Agency).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgencyExists(Agency.AgencyID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Agency).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgencyExists(Agency.AgencyID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Types = Enum.GetValues(typeof(FoodCategoryType))
                        .Cast <FoodCategoryType>()
                        .Where(f => f != FoodCategoryType.Pantry).ToList();

                return(Page());
            }

            _context.Attach(FoodCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FoodCategoryExists(FoodCategory.FoodCategoryID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Agencies.Add(Agency);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                Types = Enum.GetValues(typeof(FoodCategoryType))
                        .Cast <FoodCategoryType>()
                        .Where(f => f != FoodCategoryType.Pantry).ToList();

                return(Page());
            }

            _context.FoodCategories.Add(FoodCategory);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FoodCategory = await _context.FoodCategories.FindAsync(id);

            if (FoodCategory != null)
            {
                _context.FoodCategories.Remove(FoodCategory);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            DonationType = await _context.DonationTypes.FindAsync(id);

            if (DonationType != null)
            {
                _context.DonationTypes.Remove(DonationType);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }