public ActionResult Edit(Models.ProductType editType)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ViewBag.cateListEdit = new SelectList(dbType.Categories, "cateID", "cateName");
         try
         {
             if (ModelState.IsValid)
             {
                 dbType.Entry(editType).State = System.Data.Entity.EntityState.Modified;
                 dbType.SaveChanges();
                 ViewBag.EditTypeError = "Cập nhật loại sản phẩm thành công.";
             }
         }
         catch (Exception)
         {
             ViewBag.EditTypeError = "Không thể cập nhật loại sản phẩm.";
         }
         return(View());
     }
 }
예제 #2
0
 public IHttpActionResult AddProductType(ProductType productType)
 {
     try
     {
         var guid = Guid.NewGuid();
         Models.ProductType prod = new Models.ProductType();
         prod.Id        = guid;
         prod.IsActive  = true;
         prod.IsDeleted = false;
         prod.Type      = productType.Type;
         prod.EventId   = productType.EventId;
         //productType.Id = Guid.NewGuid();
         //productType.IsActive = true;
         //productType.IsDeleted = false;
         this.unit._productTypeRepository.Save(prod);
         if (this.unit.Commit() > 0)
         {
             return(Ok(guid));
         }
         else
         {
             return(Ok(""));
         }
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
예제 #3
0
 public ActionResult Create(Models.ProductType createType)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ViewBag.cateListCreate = new SelectList(dbType.Categories, "cateID", "cateName");
         try
         {
             if (ModelState.IsValid)
             {
                 dbType.ProductTypes.Add(createType);
                 dbType.SaveChanges();
                 ViewBag.CreateTypeError = "Thêm loại sản phẩm thành công.";
             }
         }
         catch (Exception)
         {
             ViewBag.CreateTypeError = "Không thể thêm loại sản phẩm.";
         }
         return(View());
     }
 }
예제 #4
0
        public IActionResult CreateProductTypesData()
        {
            ProductType productType1 = new Models.ProductType
            {
                Description = "Pike Place Market’s dozens of specialty food stores carry the spices, ingredients and products for nearly any kind of culinary endeavor or adventurous recipe.",
                Name        = "Specialty Foods"
            };

            productTypeRepo.Save(productType1);
            ProductType productType2 = new Models.ProductType
            {
                Description = "The Pike Place Market’s year-round produce stands, called highstalls, sell fresh fruits, vegetables, herbs, locally foraged mushrooms and seasonal favorites from around the world and from local growers.",
                Name        = "Produce"
            };

            productTypeRepo.Save(productType2);
            ProductType productType3 = new Models.ProductType
            {
                Description = "Shop at the Pike Place Market fish markets, butchers and dairy shops for fresh seafood, meat and dairy products from knowledgeable producers who know how and where the food was caught, raised or made.",
                Name        = "Fresh Fish, Meat, and Dairy"
            };

            productTypeRepo.Save(productType3);
            ProductType productType4 = new Models.ProductType
            {
                Description = "The Market is filled with delicious foods—some made right here and others from around the world. Check out the wide variety of gourmet offerings and everyday staples. ",
                Name        = "Artisan/Imported"
            };

            productTypeRepo.Save(productType4);
            return(RedirectToAction("Index"));
        }
예제 #5
0
        /// <summary>
        /// Lưu thay đổi loại Mặt hàng
        /// </summary>
        private void btnProductType_SaveChange_Click(object sender, RoutedEventArgs e)
        {
            /// Kiểm tra Id
            try
            {
                Convert.ToInt32(txtProductTypeId.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Mã số loại mặt hàng không hợp lệ", "Cập nhật loại mặt hàng", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (String.IsNullOrWhiteSpace(txtProductTypeName.Text))
            {
                MessageBox.Show(
                    "Vui lòng nhập Tên Loại Mặt hàng",
                    "Cập nhật Loại Mặt hàng",
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                return;
            }

            Models.ProductType productType = new Models.ProductType();

            productType.Id = Convert.ToInt32(txtProductTypeId.Text);

            productType.Name = txtProductTypeName.Text;

            if (cbProductTypeParentName.SelectedItem != null)
            {
                productType.ParentId = (cbProductTypeParentName.SelectedItem as Models.ProductType).Id;
            }
            else
            {
                productType.ParentId = null;
            }

            productType.Detail = txtProductTypeDetail.Text;

            if (!App.productTypeController.Update(productType))
            {
                MessageBox.Show(
                    "Cập nhật thất bại",
                    "Cập nhật Loại Mặt hàng",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show(
                    "Cập nhật thành công",
                    "Cập nhật Loại Mặt hàng",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }

            LoadProductTypeTable();
        }
예제 #6
0
        /// <summary>
        /// Thêm mới Loại Mặt hàng
        /// </summary>
        private void btnAddProductType_Click(object sender, RoutedEventArgs e)
        {
            /// Sử lý khi lần đầu ấn nút Tạo mới
            if (btnAddProductType.Content.Equals("Tạo mới"))
            {
                ClearInformations();

                btnAddProductType.Content = "Hoàn tất";

                btnAddProductType_Cancel.Visibility = Visibility.Visible;
                btnAddProductType_Cancel.IsEnabled  = true;

                btnSaveChangeProductType.IsEnabled       = false;
                btnSaveChangeProductTypeCancel.IsEnabled = false;

                btnDeleteProductType.IsEnabled = false;

                txtSearch.IsEnabled  = false;
                btnRefresh.IsEnabled = false;

                return;
            }

            if (String.IsNullOrWhiteSpace(txtProductTypeName.Text))
            {
                MessageBox.Show(
                    "Vui lòng nhập Tên Loại Mặt hàng",
                    "Thêm mới Loại Mặt hàng",
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                return;
            }

            /// Sử lý khi ấn nút Hoàn tất - Tạo mới 2
            Models.ProductType productType = new Models.ProductType();

            productType.AccountId = App.accountController.Account.Id;

            productType.Name = txtProductTypeName.Text;

            if (cbProductTypeParentName.SelectedItem != null)
            {
                productType.ParentId = (cbProductTypeParentName.SelectedItem as Models.ProductType).Id;
            }

            productType.Detail = txtProductTypeDetail.Text;

            if (App.productTypeController.Add(productType))
            {
                MessageBox.Show("Thêm mới thành công", "Thêm mới Loại Mặt hàng", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("Thêm mới thất bại", "Thêm mới Loại Mặt hàng", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            LoadProductTypeTable();
        }
예제 #7
0
        /// <summary>
        /// Đổ dữ liệu vào khung chi tiết khi click chuột vào bảng
        /// </summary>
        private void gridControl1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                ProductTypeTableModel item        = (ProductTypeTableModel)gridControl1.SelectedItem;
                Models.ProductType    productType = App.productTypeController.GetProductTypeById(item.Id);

                txtProductTypeId.Text         = productType.Id + "";
                txtProductTypeCreateTime.Text = productType.CreateTime.ToString("dd/MM/yyyy");
                txtProductTypeCreatedBy.Text  = productType.Account?.Name ?? "";

                txtProductTypeName.Text   = productType.Name;
                txtProductTypeDetail.Text = productType.Detail;

                if (productType.ParentProductType != null)
                {
                    try
                    {
                        List <Models.ProductType> cboxList = cbProductTypeParentName.ItemsSource as List <Models.ProductType>;
                        cbProductTypeParentName.SelectedItem = cboxList.Single(m => m.Id == productType.ParentId);
                    }
                    catch (Exception)
                    {
                        cbProductTypeParentName.SelectedItem = null;
                    }
                }
                else
                {
                    cbProductTypeParentName.SelectedItem = null;
                }

                btnAddProductType.IsEnabled         = true;
                btnAddProductType_Cancel.Visibility = Visibility.Hidden;
                btnAddProductType_Cancel.IsEnabled  = false;

                btnSaveChangeProductType.Visibility = Visibility.Visible;
                btnSaveChangeProductType.IsEnabled  = true;

                btnSaveChangeProductTypeCancel.Visibility = Visibility.Visible;
                btnSaveChangeProductTypeCancel.IsEnabled  = true;

                btnDeleteProductType.Visibility = Visibility.Visible;
                btnDeleteProductType.IsEnabled  = true;

                btnSearch.Visibility = Visibility.Visible;
                btnSearch.IsEnabled  = true;

                btnRefresh.Visibility = Visibility.Visible;
                btnRefresh.IsEnabled  = true;
            }
            catch (Exception ex)
            {
            }
        }
        public async Task <ActionResult <ProductType> > SaveProductType([FromBody] ProductTypeDTO _ProductTypeS)
        {
            ProductType _ProductType = _ProductTypeS;

            try
            {
                ProductType _listProductType = new ProductType();
                string      baseadress       = config.Value.urlbase;
                HttpClient  _client          = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/ProductType/GetProductTypeById/" + _ProductType.ProductTypeId);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta = await(result.Content.ReadAsStringAsync());
                    _ProductType   = JsonConvert.DeserializeObject <ProductTypeDTO>(valorrespuesta);
                }

                if (_ProductType == null)
                {
                    _ProductType = new Models.ProductType();
                }

                if (_ProductTypeS.ProductTypeId == 0)
                {
                    var insertresult = await Insert(_ProductTypeS);
                }
                else
                {
                    var updateresult = await Update(_ProductType.ProductTypeId, _ProductTypeS);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }

            return(Json(_ProductType));
        }
예제 #9
0
 public ActionResult Edit(Models.ProductType editType, string prtname)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         EX  ex = new EX();
         var a  = ex.prtname(prtname);
         int b  = a.Count();
         ViewBag.cateListEdit = new SelectList(dbType.Categories, "cateID", "cateName");
         try
         {
             if (ModelState.IsValid)
             {
                 if (b != 0)
                 {
                     ViewBag.EditTypeError = "Trùng tên loại sản phẩm.";
                 }
                 else
                 {
                     editType.typeName            = prtname;
                     dbType.Entry(editType).State = System.Data.Entity.EntityState.Modified;
                     dbType.SaveChanges();
                     SetAlert("Cập nhật loại sản phẩm thành công!", "success");
                     return(RedirectToAction("Index", "ProductType"));
                 }
             }
         }
         catch (Exception)
         {
             ViewBag.EditTypeError = "Không thể cập nhật loại sản phẩm.";
         }
         return(View());
     }
 }
 public ActionResult Create(Models.ProductType createType)
 {
     //if (Session["accname"] == null)
     //{
     //    Session["accname"] = null;
     //    return RedirectToAction("Login", "Account");
     //}
     //else
     //{
     ViewBag.cateListCreate = new SelectList(dbType.Categories, "cateID", "cateName");
     try
     {
         if (dbType.ProductTypes.SingleOrDefault(cr => cr.typeName.Equals(createType.typeName)) == null)
         {
             dbType.ProductTypes.Add(createType);
             dbType.SaveChanges();
             //ViewBag.CreateTypeError = "Thêm loại sản phẩm thành công.";
             return(RedirectToAction("Index", new { error = "Thêm loại sản phẩm thành công." }));
         }
         else
         {
             ViewBag.CreateTypeError = "Tên danh mục đã tồn tại.";
         }
         //if (ModelState.IsValid)
         //    {
         //        dbType.ProductTypes.Add(createType);
         //        dbType.SaveChanges();
         //        ViewBag.CreateTypeError = "Thêm loại sản phẩm thành công.";
         //    }
     }
     catch (Exception)
     {
         ViewBag.CreateTypeError = "Không thể thêm loại sản phẩm.";
     }
     return(View());
     //}
 }
예제 #11
0
        public ActionResult Create(Models.ProductType createType, string prtname)
        {
            if (Session["accname"] == null)
            {
                Session["accname"] = null;
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                ViewBag.cateListCreate = new SelectList(dbType.Categories, "cateID", "cateName");
                try
                {
                    EX  ex = new EX();
                    var a  = ex.prtname(prtname);
                    int b  = a.Count();

                    if (b == 0)
                    {
                        createType.typeName = prtname;
                        dbType.ProductTypes.Add(createType);

                        dbType.SaveChanges();
                        SetAlert("Thêm mới loại sản phẩm thành công!", "success");
                        return(RedirectToAction("Index", "ProductType"));
                    }
                    else
                    {
                        ViewBag.CreateTypeError = "Trùng tên loại sản phẩm.";
                    }
                }
                catch (Exception)
                {
                    ViewBag.CreateTypeError = "Không thể thêm loại sản phẩm.";
                }
                return(View());
            }
        }
예제 #12
0
        internal static GraphqlEntityContext AddUser(this GraphqlEntityContext context)
        {
            if (!context.User.Any(x => x.Identification == "InitialUSer"))
            {
                var userInit = new Models.User
                {
                    Identification = "InitialUSer"
                };

                var userCommum = new Models.User
                {
                    Identification = "userCommum"
                };

                var userSales = new Models.User
                {
                    Identification = "userSales"
                };

                context.User.Add(userInit);
                context.User.Add(userCommum);
                context.User.Add(userSales);

                var pc = new Models.ProductType
                {
                    Identification = "PC2"
                };

                context.ProductType.Add(pc);

                var placaMae = new Models.Product
                {
                    Identification = "Placa de video",
                    ProductType = pc,
                    User = userCommum
                };

                context.Product.Add(placaMae);

                context.Sale.Add(new Models.Sale
                {
                    Identification = "Initial",
                    Product = new List<Models.Product>
                    {
                        new Models.Product
                        {
                            Identification= "Placa de video",
                            ProductType =pc,
                            User = userCommum
                        },
                        placaMae
                    },
                    User = userInit
                });

                context.Sale.Add(new Models.Sale
                {
                    Identification = "Initial2",
                    Product = new List<Models.Product>
                    {
                        new Models.Product
                        {
                            Identification= "Placa de video2",
                            ProductType = pc,
                            User = userInit
                        },
                        placaMae
                    },
                    User = userInit
                });
            }

            return context;
        }
예제 #13
0
 public IEnumerable <Category> GetCategoriesByType(Models.ProductType type)
 => _dbContext.Categories.Where(f => f.Type == type);