Exemple #1
0
        private void btn_GrabarTipo_Click(object sender, EventArgs e)
        {
            if (_tipoArticulosNueno)
            {
                _contexto.Dispose();
                _contexto = new DB_Context();
                var NuevoTipoArticulo = new TipoArticulo
                {
                    Nombre      = txt_Nombre.Text,
                    Descripcion = rtb_Descripcion.Text,
                    EstasActivo = ckb_EstaAciva.Checked
                };
                _contexto.TipoArticulos.Add(NuevoTipoArticulo);
                _contexto.SaveChanges();
                MessageBox.Show(" Tipo de articulo ha sido creado exitosamente");
                this.ClearAll("all");
                this.LoadListaArticulos();
            }
            else

            {
                _contexto.Dispose();
                _contexto = new DB_Context();
                int IdTipoArticulo        = int.Parse(txt_Id.Text);
                var ModificarTipoArticulo = _contexto.TipoArticulos.FirstOrDefault(t => t.Id_TipoArticulo == IdTipoArticulo);
                ModificarTipoArticulo.Nombre      = txt_Nombre.Text;
                ModificarTipoArticulo.Descripcion = rtb_Descripcion.Text;
                ModificarTipoArticulo.EstasActivo = ckb_EstaAciva.Checked;
                _contexto.SaveChanges();
                MessageBox.Show(" Tipo de articulo ha sido Modificado exitosamente");
                this.ClearAll("all");
                this.LoadListaArticulos();
            }
        }
        public IHttpActionResult Update([FromBody] CategoryViewModel dataBody)
        {
            // membuat koneksi DB
            var db = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                // Buat Object dan menginisialisasi dengan data dari database menggunakan method Find(Primary Key)
                Category category = db.Categories.Find(dataBody.CategoryID);
                // inisialisasi data yang akan dirubah
                category.CategoryID   = dataBody.CategoryID;
                category.CategoryName = dataBody.CategoryName;
                category.Description  = dataBody.Description;
                category.Picture      = dataBody.picture;

                db.SaveChanges();

                db.Dispose();
                result.Add("Message", "Update data success");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        public IHttpActionResult Update([FromBody] ProductViewModel dataBody)
        {
            // membuat koneksi DB
            var db = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                // Buat Object dan menginisialisasi dengan data dari database menggunakan method Find(Primary Key)
                Product product = db.Products.Find(dataBody.ProductID);
                // inisialisasi data yang akan dirubah
                product.ProductID       = dataBody.ProductID;
                product.ProductName     = dataBody.ProductName;
                product.SupplierID      = dataBody.SupplierID;
                product.CategoryID      = dataBody.CategoryID;
                product.QuantityPerUnit = dataBody.QuantityPerUnit;
                product.UnitPrice       = dataBody.UnitPrice;
                product.UnitsInStock    = dataBody.UnitsInStock;
                product.UnitsOnOrder    = dataBody.UnitsOnOrder;
                product.ReorderLevel    = dataBody.ReorderLevel;
                product.Discontinued    = dataBody.Discontinued;

                db.SaveChanges();

                db.Dispose();
                result.Add("Message", "Update data success");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        //DB_Context context = new DB_Context();

        public ActionResult UploadDocument(string project = "", string uploadFile = "")
        // Uploads file from client to server - uses async task
        {
            // Check that Project Name is set, if so save it to database
            if (project != "")
            {
                // Get UrserId if logged on
                string myId = User.Identity.GetUserId();
                if (CheckExistProject(myId, project))
                {
                    ViewBag.Message = "Project " + project + " exists already. Choose another name!";
                    return(View());
                }
                DB_Context context   = new DB_Context();
                Project    myProject = new Project();
                myProject.ProjectId   = 1;
                myProject.UserId      = myId;
                myProject.ProjectName = project;
                context.Project.Add(myProject);
                context.SaveChanges();
                context.Dispose();
                // return with the action to show file content on screen
                return(RedirectToAction("FileParser", new { project = project, csvFile = uploadFile }));
                //return View("../Home/Index");
            }
            else
            {
                return(View());
            }
        }
        public IHttpActionResult Create([FromBody] CategoryViewModel dataBody)
        {
            var db = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                // Buat Object dan menginisialisasi dengan data dari body
                Category newCategory = new Category()
                {
                    CategoryID   = dataBody.CategoryID,
                    CategoryName = dataBody.CategoryName,
                    Description  = dataBody.Description,
                    Picture      = dataBody.picture
                };

                // menambahkan kategori baru ke Category Entity Database
                db.Categories.Add(newCategory);
                // method yang digunakan untuk menyimpan perubahan baru di database
                db.SaveChanges();
                db.Dispose();
                result.Add("Message", "Insert data success");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult Soal()
        {
            var DB = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                IEnumerable <ProductsViewModel> expensiveValue = DB.Products.Where(data => data.UnitPrice == DB.Products.Max(max => max.UnitPrice))
                                                                 .ToList().Select(item => new ProductsViewModel(item));
                IEnumerable <ProductsViewModel> cheapestValue = DB.Products.Where(data => data.UnitPrice == DB.Products.Min(min => min.UnitPrice))
                                                                .ToList().Select(item => new ProductsViewModel(item));
                IEnumerable <ProductsViewModel> avgValue = DB.Products.Where(data => data.UnitPrice < DB.Products.Average(avg => avg.UnitPrice))
                                                           .ToList().Select(item => new ProductsViewModel(item));

                DB.Dispose();
                result.Add("expensiveValue", expensiveValue);
                result.Add("cheapestValue", cheapestValue);
                result.Add("minAverageValue", avgValue);
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #7
0
        public IHttpActionResult Update([FormBody] CategoryViewModel databody)
        {
            var db = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                Category category = db.Categories.Find(databody.CategoryID);

                category.CategoryID   = databody.CategoryID;
                category.CategoryName = databody.CategoryName;
                category.Description  = databody.Description;
                category.Picture      = databody.Picture;

                db.SaveChanges();

                db.Dispose();

                result.Add("Message", "Update Data Success");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #8
0
        public IHttpActionResult Create([FormBody] CategoryViewModel databody)
        {
            var db = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();
                Category newCategory = new Category()
                {
                    CategoryID   = databody.CategoryID,
                    CategoryName = databody.CategoryName,
                    Description  = databody.Description,
                    Picture      = databody.Picture
                };

                db.Categories.Add(newCategory);
                db.SaveChanges();

                db.Dispose();

                result.Add("Message", "Insert Data Success");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult Filter(string productName = null, string categoryName = null, decimal?byPrice = null)
        {
            var DB = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();
                var temp = DB.Products.AsQueryable();
                if (productName != null)
                {
                    temp = temp.Where(data => data.ProductName.ToLower().Contains(productName.ToLower()));
                }
                if (categoryName != null)
                {
                    temp = temp.Where(data => data.Category.CategoryName.ToLower().Contains(categoryName.ToLower()));
                }
                if (byPrice != null)
                {
                    temp = temp.Where(data => data.UnitPrice <= byPrice);
                }


                var listProduct = temp.ToList().Select(item => new ProductsViewModel(item));

                result.Add("data", listProduct);
                DB.Dispose();
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult Create([FromBody] ProductsViewModel dataBody)
        {
            var DB = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();


                Product newProduct = new Product()
                {
                    ProductID       = dataBody.ProductID,
                    ProductName     = dataBody.ProductName,
                    SupplierID      = dataBody.SupplierID,
                    CategoryID      = dataBody.CategoryID,
                    QuantityPerUnit = dataBody.QuantityPerUnit,
                    UnitPrice       = dataBody.UnitPrice,
                    UnitsInStock    = dataBody.UnitsInStock,
                    ReorderLevel    = dataBody.ReorderLevel,
                    Discontinued    = dataBody.Discontinued
                };
                DB.Products.Add(newProduct);
                DB.SaveChanges();
                DB.Dispose();
                result.Add("Message", "Read Data Succses");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult Update([FromBody] ProductsViewModel dataBody)
        {
            var DB = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();

                Product product = DB.Products.Find(dataBody.ProductID);

                product.ProductID       = dataBody.ProductID;
                product.ProductName     = dataBody.ProductName;
                product.CategoryID      = dataBody.CategoryID;
                product.QuantityPerUnit = dataBody.QuantityPerUnit;
                product.UnitPrice       = dataBody.UnitPrice;
                product.UnitsInStock    = dataBody.UnitsInStock;
                product.ReorderLevel    = dataBody.ReorderLevel;
                product.Discontinued    = dataBody.Discontinued;

                DB.SaveChanges();
                DB.Dispose();
                result.Add("Message", "Update Data Succses");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #12
0
        private void LoadListaModelos()
        {
            _contexto.Dispose();
            _contexto = new DB_Context();
            var ListaModelos = _contexto.Modelos.Include(m => m.Marca).ToList().Where(m => m.Marca.Id_Marca == IDMarca);;

            if (ListaModelos != null)
            {
                string[] item = new string[2];
                foreach (var ListModelos in ListaModelos)
                {
                    item[0] = ListModelos.Id_Modelo.ToString();
                    item[1] = ListModelos.Nombre;
                    dgv_ListadoModelos.Rows.Add(item);
                }
            }
        }
Exemple #13
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Exemple #14
0
        //Metodos loads por el programador para llenar datagrid de Paises
        //llenar datagridPaises
        private void LoadListaPaises()
        {
            _contexto.Dispose();
            _contexto = new DB_Context();
            var ListaPaises = _contexto.Paises.ToList();

            //= _contexto.Marcas.ToList(m => m.);

            if (ListaPaises != null)
            {
                string[] item = new string[2];
                foreach (var ListPaises in ListaPaises)
                {
                    item[0] = ListPaises.Id_Pais.ToString();
                    item[1] = ListPaises.Nombre;
                    dgv_ListadoPaises.Rows.Add(item);
                }
            }
        }
Exemple #15
0
        private void LoadListaEstados()
        {
            _contexto.Dispose();
            _contexto = new DB_Context();
            //   var ListaMarcas = _contexto.Marcas.Include(m => m.TipoArticulo).ToList().Where(m => m.TipoArticulo.Id_TipoArticulo == IdTipoArticulo);

            var ListaEstados = _contexto.Estados.Include(y => y.Pais).ToList().Where(e => e.Pais.Id_Pais == IdPais);



            if (ListaEstados != null)
            {
                string[] item = new string[2];
                foreach (var ListEstados in ListaEstados)
                {
                    item[0] = ListEstados.Id_Estado.ToString();
                    item[1] = ListEstados.Nombre;
                    dgv_ListadoEstados.Rows.Add(item);
                }
            }
        }
Exemple #16
0
        public IHttpActionResult ReadAll()
        {
            // membuat koneksi DB
            var db = new DB_Context();

            try
            {
                // untuk mengambil semua data entity dan merubahnya menjadi list.
                var listProductEntity = db.Products.ToList();

                // variable List untuk menampung view model
                List <ProductViewModel> listProduct = new List <ProductViewModel>();

                // Dictionary(Map) untuk kebutuhan hasil response (jika dibutuhkan)
                Dictionary <string, object> result = new Dictionary <string, object>();

                //mapping entity ke View Model, dan menambahkan nya kedalam list View Model
                foreach (var item in listProductEntity)
                {
                    ProductViewModel product = new ProductViewModel()
                    {
                        ProductID       = item.ProductID,
                        ProductName     = item.ProductName,
                        SupplierID      = item.SupplierID,
                        CategoryID      = item.CategoryID,
                        QuantityPerUnit = item.QuantityPerUnit,
                        UnitPrice       = item.UnitPrice,
                        UnitsInStock    = item.UnitsInStock,
                        UnitsOnOrder    = item.UnitsOnOrder,
                        ReorderLevel    = item.ReorderLevel,
                        Discontinued    = item.Discontinued
                    };

                    // menambahkan object View Model ke list View Model
                    listProduct.Add(product);
                }
                ;
                // menambahkan object ke dictionary
                result.Add("Message", "Read data success");
                result.Add("Data : ", listProduct);
                db.Dispose();
                // return data response
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #17
0
        public void SetProjectstatus(int projId, string myStatus)
        {
            DB_Context context = new DB_Context();
            Project    project = context.Project.Find(projId);

            project.Status = myStatus;
            try
            {
                context.SaveChanges();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException e)
            {
                // DBUpdate error
                TempData["shortMessage"] = "DB Update failed!!";
            }
            context.Dispose();
        }
        public IHttpActionResult Delete(int ProductID)
        {
            var DB = new DB_Context();

            try
            {
                Dictionary <string, object> result = new Dictionary <string, object>();
                Product product = DB.Products.Where(data => data.ProductID == ProductID).FirstOrDefault();
                DB.Products.Remove(product);
                DB.SaveChanges();
                DB.Dispose();
                result.Add("Message", "Delete Data Succses");
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult ReadAll()
        {
            // membuat koneksi DB
            var db = new DB_Context();

            try
            {
                // untuk mengambil semua data entity dan merubahnya menjadi list.
                var listCategoryEntity = db.Categories.ToList();

                // variable List untuk menampung view model
                List <CategoryViewModel> listCategory = new List <CategoryViewModel>();

                // Dictionary(Map) untuk kebutuhan hasil response (jika dibutuhkan)
                Dictionary <string, object> result = new Dictionary <string, object>();

                //mapping entity ke View Model, dan menambahkan nya kedalam list View Model
                foreach (var item in listCategoryEntity)
                {
                    CategoryViewModel category = new CategoryViewModel()
                    {
                        CategoryID   = item.CategoryID,
                        CategoryName = item.CategoryName,
                        Description  = item.Description,
                        picture      = item.Picture
                    };

                    // menambahkan object View Model ke list View Model
                    listCategory.Add(category);
                }
                ;
                // menambahkan object ke dictionary
                result.Add("Message", "Read data success");
                result.Add("Data : ", listCategory);
                db.Dispose();
                // return data response
                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IHttpActionResult ReadAll()
        {
            var db = new DB_Context();

            try
            {
                var listProductsEntity = db.Products.ToList();

                List <ProductsViewModel> listProducts = new List <ProductsViewModel>();

                Dictionary <string, object> result = new Dictionary <string, object>();

                foreach (var item in listProductsEntity)
                {
                    ProductsViewModel products = new ProductsViewModel()
                    {
                        ProductID       = item.ProductID,
                        ProductName     = item.ProductName,
                        SupplierID      = item.SupplierID,
                        CategoryID      = item.CategoryID,
                        QuantityPerUnit = item.QuantityPerUnit,
                        UnitPrice       = item.UnitPrice,
                        UnitsInStock    = item.UnitsInStock,
                        ReorderLevel    = item.ReorderLevel,
                        Discontinued    = item.Discontinued
                    };
                    listProducts.Add(products);
                }
                ;

                result.Add("Message", "Read Data Succses");
                result.Add("Data", listProducts);

                db.Dispose();

                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public ActionResult Save_File_Data(string project, string fileName)
        // Save transferred File to database
        {
            // Use ADO instead of EF due to performance issues

            string        ADOcon       = ConfigurationManager.ConnectionStrings["ADOLucroAnalyzer"].ConnectionString;
            SqlConnection DbConnection = new SqlConnection(ADOcon);

            DbConnection.Open();

            DB_Context db     = new DB_Context();
            CSVFile    myData = new CSVFile();

            myData = UploadToObject(project, fileName);

            var projectList = db.Project.ToList();

            // Get the ProjectId for the Project Name given.

            int myProjectId = (from projItem in projectList
                               where projItem.ProjectName == project && projItem.UserId == User.Identity.GetUserId()
                               select projItem.ProjectId).FirstOrDefault();

            // Save the Properties and DataNames in the database and return their corresponding Id's (key values9 from the database model
            List <List <int> > myIDList = FillNames(myProjectId, myData.NameList, myData.TypeList);

            ProjectData myProject = new ProjectData();

            // SHow that the project is in the update status (used to show a text in the project list oin the View)
            myProject.SetProjectstatus(myProjectId, "U");

            // Fill all values for properties and datanames in the database
            myProject.FillValues(ADOcon, context: db, myProjectID: myProjectId, myIDList: myIDList, myTypeList: myData.TypeList, myValueList: myData.ValueList);

            db.SaveChanges();
            db.Dispose();
            DbConnection.Close();

            // Show project List
            return(RedirectToAction("../Projects/ProjectList"));
        }
Exemple #22
0
        public IHttpActionResult ReadAll()
        {
            //membuat koneksi database
            var db = new DB_Context();

            try
            {
                //mengambil data dan merubah menjadi list
                var listCategoryEntity = db.Categories.ToList();
                List <CategoryViewModel>    listProduct = new List <CategoryViewModel>();
                Dictionary <string, object> result      = new Dictionary <string, object>();

                foreach (var item in listCategoryEntity)
                {
                    CategoryViewModel product = new CategoryViewModel()
                    {
                        CategoryID   = item.CategoryID,
                        CategoryName = item.CategoryName,
                        Description  = item.Description,
                        Picture      = item.Picture
                    };

                    listProduct.Add(product);
                }
                ;

                result.Add("Message", "Read Data Success");
                result.Add("Data", listProduct);

                db.Dispose();

                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #23
0
        public IHttpActionResult ReadAll()
        {
            var db = new DB_Context();

            try
            {
                var listCategoryEntity = db.Categories.ToList();

                List <CategoryViewModel> listProduct = new List <CategoryViewModel>();

                Dictionary <string, object> result = new Dictionary <string, object>();

                foreach (var item in listCategoryEntity)
                {
                    CategoryViewModel category = new CategoryViewModel()
                    {
                        CategoryID   = item.CategoryID,
                        CategoryName = item.CategoryName,
                        Description  = item.Description,
                        Picture      = item.Picture
                    };
                    listProduct.Add(category);
                }
                ;

                result.Add("Message", "Read Data Succses");
                result.Add("Data", listProduct);

                db.Dispose();

                return(Ok(result));
            }
            catch (Exception)
            {
                throw;
            }
        }
        private List <List <int> > FillNames(int projectId, List <string> namesList, List <string> typeList)
        // Fill all the names of Properties and Data from the transferred file and returns their corresponding id's (key values)
        {
            DB_Context context = new DB_Context();

            // Initiate for table PropNames
            var namePropList = context.PropertyName.ToList();
            int lastPropertyId;

            // Get last PropertyId in PropertyName
            try
            {
                lastPropertyId = (from nameItem in namePropList
                                  orderby nameItem.PropertyId
                                  select nameItem.PropertyId).Last();
            }
            catch (InvalidOperationException e)
            {
                // if table PropertyName is empty set lastPropertyId = 0
                lastPropertyId = 0;
            }

            // Initiate for table DataNames
            var nameDataList = context.DataName.ToList();
            int lastDataId;

            // Get last DataId in DataNames
            try
            {
                lastDataId = (from nameItem in nameDataList
                              orderby nameItem.DataId
                              select nameItem.DataId).Last();
            }
            catch (InvalidOperationException e)
            {
                // if table DataNames is empty set lastDatId = 0
                lastDataId = 0;
            }

            List <int> myPropIdList = new List <int>();
            List <int> myDataIdList = new List <int>();

            int counter = 0;

            // Fill property and data names in database
            foreach (string item in namesList)
            {
                if (typeList[counter] == "S")
                {
                    PropName myPropName = new PropName();
                    lastPropertyId++;
                    myPropName.PropertyId = lastPropertyId;
                    context.PropertyName.Add(new PropName {
                        ProjectId = projectId, PropertyName = item
                    });
                }
                else
                {
                    DataName myDataName = new DataName();
                    lastDataId++;
                    myDataName.DataId = lastDataId;
                    context.DataName.Add(new DataName {
                        ProjectId = projectId, Data_Name = item
                    });
                }
                counter++;
            }
            context.SaveChanges();

            // Get the id's (key values) for the Properties of this project
            var myPropList = from names in context.PropertyName where names.ProjectId == projectId select names.PropertyId;

            foreach (var item in myPropList)
            {
                myPropIdList.Add(item);
            }

            // Get the id's (key values) for the Data Names of this project
            var myDataList = from names in context.DataName where names.ProjectId == projectId select names.DataId;

            foreach (var item in myDataList)
            {
                myDataIdList.Add(item);
            }
            context.Dispose();
            List <List <int> > returnList = new List <List <int> >();

            returnList.Add(myPropIdList);
            returnList.Add(myDataIdList);
            return(returnList);
        }