Exemplo n.º 1
0
        public string Delete(Store st)
        {
            if (dbcontext == null)
            {
                dbcontext = new RouteOptimizationDBEntities();
            }

            //dbcontext.Entry(st).State = EntityState.Deleted;

            dbcontext.Stores.Remove(st);
            dbcontext.SaveChanges();
            return "";
        }
Exemplo n.º 2
0
        public IEnumerable<Store> AddorUpdate(Store st)
        {
            if (dbcontext == null)
            {
                dbcontext = new RouteOptimizationDBEntities();
            }

            if (st.StoreID > 0)
            {
                Store store;
                store = GetById(st.StoreID);
                dbcontext.Entry(store).CurrentValues.SetValues(st);
                // dbcontext.Entry(store).State = EntityState.Modified;
            }
            else
            {
                dbcontext.Stores.Add(st);
            }
            dbcontext.SaveChanges();
            return dbcontext.Stores.ToList();
        }
        public string Create(string Address1,string Address2, string Postal, int Country, int Province, int City, int ID, string Name, string StoreNumber, int RetailerID, string EmailID, string Phone)
        {
            StoreDAL storeBO = new StoreDAL();

            Store store = new Store();
            Address ad = new Address();
            ad.Address1 = Address1;
            ad.Address2 = Address2;
            ad.PostalCode = Postal;
            ad.CityID = City;
            ad.CountryID = Country;
            ad.ProvinceID = Province;
            int addid = 0;
            if (ModelState.IsValid)
            {

                storeBO.AddorUpdateAddress(ad);
                var result = db.Addresses.OrderByDescending(x => x.AddressID).First();
                addid = result.AddressID;
            }
            if (!ID.Equals(0))
            {
                store.StoreID = ID;
            }
            store.Name = Name;
            store.StoreNumber = StoreNumber;
            store.RetailerID = RetailerID;
            store.EmailID = EmailID;
            store.Phone = Phone;
            if (addid != 0)
            {

                store.AddressID = addid;
            }
            storeBO.AddorUpdate(store);
            return ("Added");
        }