public string Index(Order purchase)
        {
            purchase.DateTime = GetTodayTime();

            CountryContext.Orders.Add(purchase);
            CountryContext.SaveChanges();

            return($"Уважаемый, заказчик, после проверки введенных данных заявку будет опубликована");
        }
        public ActionResult DeleteCountry(int id)
        {
            var     result  = false;
            Country country = db.Countries.Find(id);

            db.Countries.Remove(country);
            db.SaveChanges();
            result = true;
            return(Json(new { success = result }, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "CustomerID,CustomerName,CustomerPIN")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create(Country country)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
示例#5
0
        public void Update(Region region)
        {
            _context.Entry(region).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }
        }
示例#6
0
        public void Save <T>(T entity) where T : Entity
        {
            var saveEntity = entity as CountryEntity;

            if (saveEntity == null)
            {
                throw new System.Exception("Can't save empty entity");
            }

            using (var context = new CountryContext())
            {
                context.Countries.Add(saveEntity);
                context.SaveChanges();
            }
        }
示例#7
0
        public void Save <T>(List <T> entities) where T : Entity
        {
            var saveEntityList = entities as List <CountryEntity>;

            if (saveEntityList == null)
            {
                throw new System.Exception("Can't save empty entity");
            }

            using (var context = new CountryContext())
            {
                foreach (var saveEntity in saveEntityList)
                {
                    context.Countries.Add(saveEntity);
                }

                context.SaveChanges();
            }
        }
        public CountriesController(CountryContext context, StateContext stateContext)
        {
            _context      = context;
            _stateContext = stateContext;

            if (_context.Countries.Count() == 0)
            {
                Country country = new Country {
                    Name = "United States", Code = "US"
                };
                State state = new State {
                    Name = "Virginias", Code = "VA", Country = country, CountryId = country.CountryId
                };
                _stateContext.States.Add(state);
                _context.Countries.Add(country);
                _context.SaveChanges();
                _stateContext.SaveChanges();
            }
        }
示例#9
0
 public void Create(Country entity)
 {
     _context.Countries.Add(entity);
     _context.SaveChanges();
 }
 public void Create(Country obj)
 {
     Context.Countries.Add(obj);
     Context.SaveChanges();
 }
示例#11
0
        static void Main(string[] args)
        {
            string countryView;

            countryView = Console.ReadLine();

            using (var context = new CountryContext())
            {
                var streetsOne = new List <Street>
                {
                    new Street
                    {
                        StreetName = "Baraeva"
                    },
                    new Street
                    {
                        StreetName = "Moldagulova"
                    },
                    new Street
                    {
                        StreetName = "Pobeda"
                    }
                };
                var streetsTwo = new List <Street>
                {
                    new Street
                    {
                        StreetName = "Furmanova"
                    },
                    new Street
                    {
                        StreetName = "Navoi"
                    },
                    new Street
                    {
                        StreetName = "Tole Bi"
                    }
                };
                var cities = new List <City>
                {
                    new City
                    {
                        CityName = "Astana", Streets = streetsOne
                    },
                    new City
                    {
                        CityName = "Almaty", Streets = streetsTwo
                    }
                };
                var country = new Country
                {
                    CountryName = "Kazakhstan", Citys = cities
                };

                context.Streets.AddRange(streetsOne);
                context.Streets.AddRange(streetsTwo);

                context.Cities.AddRange(cities);
                context.Countries.Add(country);

                context.SaveChanges();

                var resultCountry = context.Countries.Where(countryRes => countryRes.CountryName.Contains(countryView)).FirstOrDefault();
                var resultCity    = context.Cities.Where(city => city.CountryId == resultCountry.Id).FirstOrDefault();
                var resultStreet  = context.Streets.Where(street => street.CityId == resultCity.Id).ToList();

                foreach (var street in resultStreet)
                {
                    Console.WriteLine(street.StreetName);
                }



                var deleted = new Deleted
                {
                    DeletedObjectId = resultStreet.ToList()[1].Id
                };
                context.Streets.ToList()[1].Delete = true;

                var updated = new Updated
                {
                    UpdatedObjectId = resultStreet.ToList()[2].Id,
                    OldNameObject   = resultStreet.ToList()[2].StreetName
                };
                context.Streets.ToList()[2].StreetName = "Abay";
                context.SaveChanges();
            }
        }
示例#12
0
 public void Create(City entity)
 {
     _context.Cities.Add(entity);
     _context.SaveChanges();
 }