Пример #1
0
        public JsonResult UpdateProduct(APIProduct _product)
        {
            var restResult = new RestModel();

            try
            {
                product updateModel = new product();
                updateModel = db.products.Find(_product.id);

                updateModel.cat_id = _product.cat_id;
                updateModel.name   = _product.name;
                updateModel.price  = _product.price;
                updateModel.img    = _product.img;
                updateModel.note   = _product.note;

                db.Entry(updateModel).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }

            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public JsonResult InsertProduct(APIProduct _product)
        {
            var restResult = new RestModel();

            try
            {
                db.products.Add(new product()
                {
                    cat_id     = _product.cat_id,
                    name       = _product.name,
                    price      = _product.price,
                    img        = _product.img,
                    note       = _product.note,
                    is_deleted = 0
                });
                db.SaveChanges();
                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }
            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public JsonResult DeleteCategory(APICategory _category)
        {
            var restResult = new RestModel();

            try
            {
                category updateModel = new Models.category();

                updateModel = db.categories.Find(_category.id);

                updateModel.is_deleted = 1;

                db.Entry(updateModel).State = EntityState.Modified;
                db.SaveChanges();

                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }

            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
 public bool delRestaurant(RestModel SelectedRestaurant)
 {
     using (var db = new SQLite.SQLiteConnection(App.DBPath))
     {
         try
         {
             int success = db.Delete(new RestTable()
             {
                 Id              = SelectedRestaurant.ID,
                 RestName        = SelectedRestaurant.RestName,
                 RestAddress     = SelectedRestaurant.RestAddress,
                 RestPhone       = SelectedRestaurant.RestPhone,
                 RestFood        = SelectedRestaurant.RestFood,
                 RestDescription = SelectedRestaurant.RestDescription,
                 RestPicture1    = SelectedRestaurant.RestPicture1,
                 RestPicture2    = SelectedRestaurant.RestPicture2
             });
             return(true);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Пример #5
0
        public ObservableCollection <RestModel> GetRestaurants()
        {
            ObservableCollection <RestModel> restaurantList = new ObservableCollection <RestModel>();

            using (var db = new SQLite.SQLiteConnection(App.DBPath))
            {
                var myRestaurants = db.Table <RestTable>().OrderBy(s => s.RestName);
                foreach (var aRestaurant in myRestaurants)
                {
                    var restaurant = new RestModel()
                    {
                        ID              = aRestaurant.Id,
                        RestName        = aRestaurant.RestName,
                        RestAddress     = aRestaurant.RestAddress,
                        RestPhone       = aRestaurant.RestPhone,
                        RestFood        = aRestaurant.RestFood,
                        RestDescription = aRestaurant.RestDescription,
                        RestPicture1    = aRestaurant.RestPicture1,
                        RestPicture2    = aRestaurant.RestPicture2
                    };
                    restaurantList.Add(restaurant);
                }
            }
            return(restaurantList);
        }
        protected virtual async Task SavePropertiesAsync(RestModel <TEntity> restModel, TEntity entity)
        {
            var properties = restModel.PropertiesGroups?.Select(s => s.GetPropertiesEntry()).ToList();

            if (properties != null)
            {
                foreach (var propertiesEntry in properties)
                {
                    foreach (var val in propertiesEntry.Properties)
                    {
                        await PropertiesProvider.SetAsync(val.Value, entity, val.SiteId);
                    }
                }
            }
        }
Пример #7
0
        public void TestAddRestaurant()
        {
            var restaurants = new ObservableCollection <RestModel>();
            var r           = new RestModel();

            r.ID              = 12345;
            r.RestAddress     = "test";
            r.RestDescription = "test";
            r.RestFood        = "test";
            r.RestName        = "test";
            r.RestPhone       = 544654;
            r.RestPicture1    = "test";
            r.RestPicture2    = "test";
            restaurants.Add(r);
            Assert.IsNotNull(restaurants);
        }
Пример #8
0
        public JsonResult GetProduct()
        {
            var restResult = new RestModel();

            try
            {
                var products = new List <APIProduct>();
                var data     = db.products.Where(x => x.is_deleted == 0);
                foreach (var item in data)
                {
                    products.Add(new APIProduct()
                    {
                        id       = item.id,
                        cat_id   = item.category.id,
                        cat_name = item.category.name,
                        name     = item.name,
                        price    = item.price,
                        img      = item.img,
                        note     = item.note
                    });
                }

                var categories = new List <APICategory>();
                var cat        = db.categories.Where(x => x.is_deleted == 0);
                foreach (var item in cat)
                {
                    categories.Add(new APICategory()
                    {
                        id   = item.id,
                        name = item.name
                    });
                }

                restResult.data       = products;
                restResult.other_data = categories;

                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }

            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #9
0
        public JsonResult InsertCategory(APICategory _category)
        {
            var restResult = new RestModel();

            try
            {
                db.categories.Add(new category()
                {
                    name       = _category.name,
                    is_deleted = 0
                });
                db.SaveChanges();
                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }
            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        public JsonResult GetCategory()
        {
            var restResult = new RestModel();

            try
            {
                var categories = new List <APICategory>();
                var data       = db.categories.Where(x => x.is_deleted == 0);

                foreach (var item in data)
                {
                    //// Tao obj moi
                    //APICategory viewItem = new APICategory();
                    //viewItem.id = item.id;
                    //viewItem.name = item.name;

                    //categories.Add(viewItem);


                    categories.Add(new APICategory()
                    {
                        id   = item.id,
                        name = item.name
                    });
                }

                restResult.data   = categories;
                restResult.status = true;
            }
            catch (Exception ex)
            {
                restResult.status  = false;
                restResult.message = ex.Message;
            }
            return(Json(restResult, JsonRequestBehavior.AllowGet));
        }
Пример #11
0
 public bool addRestaurant(RestModel NewRestaurant)
 {
     using (var db = new SQLite.SQLiteConnection(App.DBPath))
     {
         try
         {
             var           existingRestaurant = (db.Table <RestTable>().Where(s => s.RestAddress == NewRestaurant.RestAddress)).SingleOrDefault();
             MessageDialog md;
             if (!string.IsNullOrEmpty(NewRestaurant.RestAddress) && existingRestaurant == null)
             {
                 int success = db.Insert(new RestTable()
                 {
                     Id              = NewRestaurant.ID,
                     RestName        = NewRestaurant.RestName,
                     RestAddress     = NewRestaurant.RestAddress,
                     RestPhone       = NewRestaurant.RestPhone,
                     RestFood        = NewRestaurant.RestFood,
                     RestDescription = NewRestaurant.RestDescription,
                     RestPicture1    = NewRestaurant.RestPicture1,
                     RestPicture2    = NewRestaurant.RestPicture2
                 });
                 return(true);
             }
             else
             {
                 md = new MessageDialog("Place at this address already exist.");
             }
             md.ShowAsync();
             return(false);
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
Пример #12
0
        public void Process()
        {
            var config   = this.GeneratorConfiguration;
            var assembly = new AssemblyProvider.Web.Entities.Assembly(this.entitiesAssembly, t => t.BaseType == typeof(DbContext));  // todo for code-first

            WriteLine("\r\n**** CurrentPass: {0} {1}\r\n", PrintMode.Any, config.CurrentPass, "*".Repeat(25));

            foreach (var restModelItem in entitiesProject.RestModels)
            {
                var model = new RestModel(new System.IO.FileInfo(restModelItem.FileName), config.AdditionalOptions, nameSpace);

                model.OnGetAttributes += Model_OnGetAttributes;
                model.OnGetAddIns     += Model_OnGetAddIns;
                model.OnGetOverrides  += Model_OnGetOverrides;

                foreach (var container in model.Containers)
                {
                    if (container is RestEntityContainer)
                    {
                        container.RegisterFacetHandlerType <WebAPIRestConfigJsonFacetHandler>();
                        container.RegisterFacetHandlerType <WebAPIRestProviderDataContextFacetHandler>();
                        container.RegisterFacetHandlerType <WebAPIRestServiceProviderFacetHandler>();
                    }

                    this.QueueContainerAction(container, () =>
                    {
                        using (this.GeneratorConfiguration.BeginChild(container))
                        {
                            ProcessContainer(container);
                        }
                    });
                }
            }

            foreach (var modelItem in entitiesProject.EDMXModels)
            {
                var model = new Model(new System.IO.FileInfo(modelItem.FileName), nameSpace);

                model.OnGetAttributes += Model_OnGetAttributes;
                model.OnGetAddIns     += Model_OnGetAddIns;
                model.OnGetOverrides  += Model_OnGetOverrides;

                foreach (var container in model.Containers)
                {
                    this.QueueContainerAction(container, () =>
                    {
                        using (this.GeneratorConfiguration.BeginChild(container))
                        {
                            ProcessContainer(container);
                        }
                    });
                }
            }

            while (containerActionQueue.Count > 0)
            {
                var containerProcess = containerActionQueue.Dequeue();
                var action           = containerProcess.Action;

                action();
            }

            config.Terminate();

            if (generatorOptions.GeneratorPass != GeneratorPass.All || config.CurrentPass == GeneratorPassCommon.Last)
            {
                if (generatorMode == GeneratorMode.Console)
                {
                    var packageInstalls = config.PackageInstalls;

                    WriteLine("\r\nHit any key to exit", PrintMode.Any);
                }

                ReadKey();
            }
        }