public async Task <IActionResult> Create(AddDistrictViewModel model)
        {
            if (ModelState.IsValid)
            {
                await Context.Districts.AddAsync(new District
                {
                    Name       = model.Name,
                    NameAr     = model.NameAr,
                    City       = model.City,
                    Department = model.Department,
                    ZipCode    = model.ZipCode,
                    Street     = model.Street
                }).ConfigureAwait(false);

                await Context.SaveChangesAsync().ConfigureAwait(false);

                return(RedirectToAction("Index", "Volunteers"));
            }

            return(View(model));
        }
Пример #2
0
        public void AddDistrict(AddDistrictViewModel model)
        {
            try
            {
                if (model != null)
                {
                    MasterDistrict entity = new MasterDistrict();
                    entity.DistrictName = model.DistrictName;
                    entity.StateRowID   = model.StateRowID;
                    entity.CountryRowID = model.CountryRowID;

                    db.MasterDistricts.Add(entity);
                }
                else
                {
                    throw new Exception("District could not be blank!");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }