public object GetProductCategory(int id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Product_Category objectProductCategory = new Product_Category();
            dynamic          toReturn = new ExpandoObject();

            try
            {
                objectProductCategory = db.Product_Category.Find(id);

                if (objectProductCategory == null)
                {
                    toReturn.Message = "Record Not Found";
                }
                else
                {
                    toReturn = objectProductCategory;
                }
            }
            catch
            {
                toReturn.Message = "Search Interrupted.Retry";
            }

            return(toReturn);
        }
        public async Task <IActionResult> PutProductCategory(int id, ProductCategoryVM pcvm)
        {
            if (id != pcvm.Product_Category_ID)
            {
                return(BadRequest());
            }

            Product_Category pc = new Product_Category();

            pc.Product_Category_ID   = Convert.ToInt32(pcvm.Product_Category_ID);
            pc.Product_Category_Name = pcvm.Product_Category_Name;

            db.Entry(pc).State = EntityState.Modified;
            await db.SaveChangesAsync();

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Product_CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public ActionResult Edit([Bind(Include = "Id,Title,image,describe,detail,price,status,extension")] Product product, int[] categores)
        {
            if (ModelState.IsValid)
            {
                product.date            = DateTime.Now;
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();

                List <Product_Category> datas = product.Product_Category.ToList();
                foreach (Product_Category data in datas)
                {
                    if (categores.Where(i => i == data.Id) == null)
                    {
                        db.Product_Category.Remove(data);
                    }
                }
                foreach (int id in categores)
                {
                    Product_Category val = db.Product_Category.FirstOrDefault(t => t.Category_Id == id && t.Product_Id == product.Id);
                    if (val == null)
                    {
                        Product_Category Product_Category = new Product_Category();
                        Product_Category.Category_Id = id;
                        Product_Category.Product_Id  = product.Id;
                        product.Product_Category.Add(Product_Category);
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Пример #4
0
        public ActionResult AddCategory(CategoryModel category)
        {
            var Pcategory = new Product_Category
            {
                Type        = category.Main_Category.Type,
                Description = category.Main_Category.Description
            };

            db.Product_Category.Add(Pcategory);
            db.SaveChanges();

            int id = Pcategory.ID;

            try
            {
                for (int i = 0; i < category.New_Sub_Category.Count(); i++)
                {
                    var NewSubCategory = new Sub_Product_Category
                    {
                        PC_ID       = id,
                        Type        = category.New_Sub_Category[i].Type,
                        Description = category.New_Sub_Category[i].Description
                    };
                    db.Sub_Product_Category.Add(NewSubCategory);
                    db.SaveChanges();
                }
            }catch (Exception ex)
            {
            }

            return(RedirectToAction("MaintainCategory"));
        }
Пример #5
0
        public long UpdateProductCategory(Product_Category entity)
        {
            var cate = da.Product_Category.Find(entity.ID);

            if (cate != null)
            {
                try
                {
                    // set data
                    cate.ID           = entity.ID;
                    cate.Name         = entity.Name;
                    cate.DisplayOrder = entity.DisplayOrder;
                    cate.Status       = entity.Status;
                    cate.del_flg      = Constant.DeleteFlag.NON_DELETE;
                    cate.ModifiedDate = DateTime.Now;
                    cate.ModifiedBy   = CmnEntityModel.ID;

                    da.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(0);
            }

            return(entity.ID);
        }
Пример #6
0
        public long InsertProductCategory(ProductCategoryModel model)
        {
            long res = 0;
            // Declare new DataAccess object
            ProductCategoryDa dataAccess = new ProductCategoryDa();

            using (var transaction = new TransactionScope())
            {
                try
                {
                    Product_Category cate = new Product_Category();
                    cate.ID           = model.ID;
                    cate.Name         = model.Name;
                    cate.DisplayOrder = model.DisplayOrder;
                    cate.Status       = model.Status;
                    cate.del_flg      = Constant.DeleteFlag.NON_DELETE;
                    res = dataAccess.InsertProductCategory(cate);

                    if (res <= 0)
                    {
                        transaction.Dispose();
                    }
                    transaction.Complete();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message, ex);
                }
                finally
                {
                    transaction.Dispose();
                }
            }
            return(res);
        }
Пример #7
0
        public string getCategoryName(long Id)
        {
            Product_Category cate         = da.Product_Category.Where(s => s.ID == Id).SingleOrDefault();
            string           CategoryName = cate != null?cate.Name.ToUpper() : "";

            return(CategoryName);
        }
Пример #8
0
 private void LoadChildProductCatalog(Entities db, Product_Category item)
 {
     foreach (var childItem in item.Product_CategoryChild)
     {
         LoadChildProductCatalog(db, childItem);
     }
 }
        public IHttpActionResult PutProduct_Category(int id, Product_Category product_Category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product_Category.Product_Category_ID)
            {
                return(BadRequest());
            }

            db.Entry(product_Category).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Product_CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutProduct_Category([FromRoute] int id, [FromBody] Product_Category product_Category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product_Category.ID)
            {
                return(BadRequest());
            }

            _context.Entry(product_Category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Product_CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #11
0
        public IActionResult Create([FromBody] JObject data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Product model    = data["product"].ToObject <Product>();
            var     _listImg = data["images"].ToList();
            var     _listCat = data["categories"].ToList();

            Product Created = _service.Add(model);

            for (int i = 0; i < _listImg.Count; i++)
            {
                Product_Image toCreate = new Product_Image()
                {
                    ImageID   = (int)_listImg[i],
                    ProductID = Created.Id,
                };
                _service_img.Add(toCreate);
            }
            for (int i = 0; i < _listCat.Count; i++)
            {
                Product_Category toCreate = new Product_Category()
                {
                    ProductID  = Created.Id,
                    CategoryID = (int)_listCat[i],
                };
                _service_cat.Add(toCreate);
                Category toUpdate = _catrepository.GetSingleById(toCreate.Id);
                toUpdate.Quantity++;
                _catrepository.Update(toUpdate);
            }
            return(Ok("Success"));
        }
 public bool CapNhatProduct_Category(Product_Category nv)
 {
     XoaProduct_Category(nv.id);
     db.Product_Categories.InsertOnSubmit(nv);
     db.SubmitChanges();
     return(true);
 }
        public object UpdateProductCategory(Product_Category productCategoryUpdate)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Product_Category objectProductCategory = new Product_Category();
            dynamic          toReturn = new ExpandoObject();
            var id = productCategoryUpdate.ProductCategoryID;

            try
            {
                objectProductCategory = db.Product_Category.Where(x => x.ProductCategoryID == id).FirstOrDefault();
                if (objectProductCategory != null)
                {
                    objectProductCategory.PCatName        = productCategoryUpdate.PCatName;
                    objectProductCategory.PCatDescription = productCategoryUpdate.PCatDescription;

                    db.SaveChanges();

                    toReturn.Message = "Update Successfull";
                }
                else
                {
                    toReturn.Message = "Record Not Found";
                }
            }

            catch (Exception)
            {
                toReturn.Message = "Update UnSuccessfull";
            }
            return(toReturn);
        }
        public async Task <object> Edite(Product_Category product_Category)
        {
            bool isValid = await _product_CategoryService.ModifyProduct_Category(product_Category);

            _notification.SetNotificationMessage(isValid, Title, product_Category.UID);

            return(_notification);
        }
        public bool XoaProduct_Category(int maProduct_Category)
        {
            Product_Category Product_Category = db.Product_Categories.Single(x => x.id == maProduct_Category);

            db.Product_Categories.DeleteOnSubmit(Product_Category);
            db.SubmitChanges();
            return(true);
        }
Пример #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            Product_Category product_Category = db.Product_Category.Find(id);

            db.Product_Category.Remove(product_Category);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #17
0
        public long InsertProductCategory(Product_Category entity)
        {
            entity.CreatedDate = DateTime.Now;
            entity.CreatedBy   = CmnEntityModel.ID;

            da.Product_Category.Add(entity);
            da.SaveChanges();
            return(entity.ID);
        }
Пример #18
0
        public List <Product_Type> getProductType(string id)
        {
            db.Configuration.ProxyCreationEnabled = false;

            Product_Category    product_Category = db.Product_Category.Where(x => x.Description == id).FirstOrDefault();
            List <Product_Type> types            = db.Product_Type.Where(x => x.Product_Category_ID == product_Category.Product_Category_ID).ToList();

            return(types);
        }
        public bool UpdateProduct_Category(int id, string name, string description)
        {
            Product_Category Product_Category = new Product_Category();

            Product_Category.id          = id;
            Product_Category.name        = name;
            Product_Category.description = description;
            return(PM.CapNhatProduct_Category(Product_Category));
        }
Пример #20
0
 public ActionResult Edit([Bind(Include = "prod_category_id,prod_category_name")] Product_Category product_Category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product_Category));
 }
Пример #21
0
 public Product_Category GetProductCatalog(int id)
 {
     using (Entities db = new Entities())
     {
         Product_Category productCatalog = db.Product_Category
                                           //.Include(c=>c.Superior_Agent)
                                           .AsNoTracking()
                                           .FirstOrDefault(e => e.id == id);
         return(productCatalog);
     }
 }
Пример #22
0
 public ActionResult Edit([Bind(Include = "productCategory_Id,model_Id,name,description,")] Product_Category product_Category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product_Category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.model_Id = new SelectList(db.models, "model_Id", "name");//, product_Category.model_Id);
     return(View(product_Category));
 }
Пример #23
0
 public ActionResult Create([Bind(Include = "Id,category_name")] Product_Category product_Category)
 {
     if (ModelState.IsValid)
     {
         db.Product_Category.Add(product_Category);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ActionTitle = "Create ";
     return(View(product_Category));
 }
        public IHttpActionResult GetProduct_Category(int id)
        {
            Product_Category product_Category = db.Product_Category.Find(id);

            if (product_Category == null)
            {
                return(NotFound());
            }

            return(Ok(product_Category));
        }
Пример #25
0
        public ActionResult Create([Bind(Include = "prod_category_id,prod_category_name")] Product_Category product_Category)
        {
            if (ModelState.IsValid)
            {
                db.Product_Categories.Add(product_Category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product_Category));
        }
Пример #26
0
        private void InitRowCategory(ref ExcelWorksheet ws, Product_Category cat, int row, int numOfCols)
        {
            ws.Cells[row, 1].Value = cat.Name;

            ws.Cells[row, 1].Style.Font.Bold = true;

            ws.Cells[row, 1].Style.Font.Size = 11;

            ws.Cells[row, 1, row, numOfCols].Merge = true;
            ws.Cells[row, 1, row, numOfCols].Style.Fill.PatternType = ExcelFillStyle.Solid;
            ws.Cells[row, 1, row, numOfCols].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(230, 232, 235));
        }
        public async Task <IActionResult> PostProduct_Category([FromBody] Product_Category product_Category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Product_Categories.Add(product_Category);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProduct_Category", new { id = product_Category.ID }, product_Category));
        }
Пример #28
0
        public NormalResult CreateProductCatalog(Product_Category productCatalog)
        {
            //productCatalog.Id = Guid.NewGuid();

            using (Entities db = new Entities())
            {
                db.Product_Category.Add(productCatalog);
                db.SaveChanges();
            }

            return(new NormalResult());
        }
        public IHttpActionResult PostProduct_Category(Product_Category product_Category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Product_Category.Add(product_Category);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = product_Category.Product_Category_ID }, product_Category));
        }
        public bool ThemProduct_Category(Product_Category Product_Category)
        {
            Product_Category.id = ListProduct_Categorys().Count;

            while (KiemTraTrungTonTaiProduct_Category(Product_Category.id))
            {
                Product_Category.id++;
            }
            db.Product_Categories.InsertOnSubmit(Product_Category);
            db.SubmitChanges();
            return(true);
        }