public void UpdateProduct(tblProduct tblproduct)
 {
     _da.UpdateProduct(tblproduct);
 }
 partial void DeletetblProduct(tblProduct instance);
 public void InsertProduct(tblProduct tblProduct)
 {
     _da.InsertProduct(tblProduct);
 }
 partial void InserttblProduct(tblProduct instance);
 partial void UpdatetblProduct(tblProduct instance);
		private void detach_tblProducts(tblProduct entity)
		{
			this.SendPropertyChanging();
			entity.tblCategory = null;
		}
        public ActionResult ViewProduct(Guid? newsID, byte? type)
        {
            ViewData["Type"] = type;
            if (newsID != null && !newsID.Equals(Guid.Empty))
            {
                if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
                {
                    tblProduct tblproduct = _nguyenHiepService.GetProductByID((Guid)newsID,true);
                    return View(tblproduct);
                }
                else
                {
                    tblProduct tblproduct = _nguyenHiepService.GetProductByID((Guid)newsID,false);
                    return View(tblproduct);
                }

            }
            else if (TempData["ProductID"] != null)
            {
                if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
                {
                    tblProduct tblproduct = _nguyenHiepService.GetProductByID((Guid)TempData["ProductID"],true);
                    return View(tblproduct);
                }
                else
                {
                    tblProduct tblproduct = _nguyenHiepService.GetProductByID((Guid)TempData["ProductID"],false);
                    return View(tblproduct);
                }
            }
            tblProduct tblpro = new tblProduct();
            return View(tblpro);
        }
        public ActionResult EditProduct(Guid? newsID, byte? type)
        {
            ViewData["Type"] = type;
            byte tmpType = NguyenHiep.Common.NewsTypes.NormalProduct;
            if (type.HasValue)
            {
                tmpType = (byte)type;
            }
            #region delete
            if (Request["Delete"] != null)
            {
                if (newsID.HasValue && !newsID.Equals(Guid.Empty))
                {
                    _nguyenHiepService.DeleteProduct((Guid)newsID);

                    if (tmpType == NguyenHiep.Common.NewsTypes.NormalProduct)
                    {
                        return RedirectToAction("IndexForProduct");
                    }else if (tmpType == NguyenHiep.Common.NewsTypes.PromotionNew)
                    {
                        return RedirectToAction("IndexForPromotionNews");
                    }
                    else
                    {
                        return RedirectToAction("IndexForProduct");
                    }
                }
            }
            #endregion
            List<SelectListItem> categories = new List<SelectListItem>();
            List<tblCategory> listCategory = new List<tblCategory>();
            if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
            {
                listCategory = _nguyenHiepService.GetAllCategory(true);
            }
            else
            {
                listCategory = _nguyenHiepService.GetAllCategory(false);
            }
            int counter = 0;
            foreach (tblCategory cat in listCategory)
            {
                if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
                {
                    categories.Add(new SelectListItem { Text = cat.CategoryNameEN, Value = cat.ID.ToString() });
                }
                else
                {
                    categories.Add(new SelectListItem { Text = cat.CategoryNameVN, Value = cat.ID.ToString() });
                }

            }
            List<SelectListItem> storeStatusVN = new List<SelectListItem>();
            storeStatusVN.Add((new SelectListItem { Text = "Còn hàng", Value = StoreStatuses.Exhausted.ToString() }));
            storeStatusVN.Add((new SelectListItem { Text = "Hết hàng", Value = StoreStatuses.NotExhausted.ToString() }));
            List<SelectListItem> storeStatusEN = new List<SelectListItem>();
            storeStatusEN.Add((new SelectListItem { Text = "Available", Value = StoreStatuses.Exhausted.ToString() }));
            storeStatusEN.Add((new SelectListItem { Text = "Not Available", Value = StoreStatuses.NotExhausted.ToString() }));

            List<SelectListItem> promotionVN = new List<SelectListItem>();
            promotionVN.Add((new SelectListItem { Text = "Không có khuyến mãi", Value = Promoted.NotHas.ToString() }));
            promotionVN.Add((new SelectListItem { Text = "Có khuyến mãi", Value = Promoted.Has.ToString() }));

            List<SelectListItem> promotionEN = new List<SelectListItem>();
            promotionEN.Add((new SelectListItem { Text = "Not Promoted", Value = Promoted.NotHas.ToString() }));
            promotionEN.Add((new SelectListItem { Text = "Promoted", Value = Promoted.Has.ToString() }));

            if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
            {
                ViewData["StoreStatus"] = storeStatusEN;

                ViewData["Promotion"] = promotionEN;
            }
            else
            {
                ViewData["Promotion"] = promotionVN;
                ViewData["StoreStatus"] = storeStatusVN;
            }

            ViewData["Categories"] = categories;

            if (newsID != null)
            {
                tblProduct tblproduct = new tblProduct();
                if (Request.Cookies["Culture"] != null && Request.Cookies["Culture"].Value == "en-US")
                {
                    tblproduct = _nguyenHiepService.GetProductByID((Guid)newsID,true);
                }
                else
                {
                    tblproduct = _nguyenHiepService.GetProductByID((Guid)newsID,false);
                }
                if (tblproduct != null && !string.IsNullOrEmpty(tblproduct.Description))
                {
                    ViewData["Description"] = tblproduct.Description;
                }

                return View(tblproduct);
            }
            else
            {

                ViewData["AddProduct"] = true;
                tblProduct tblproduct = new tblProduct();
                return View(tblproduct);
            }
        }
 public void UpdateProduct(tblProduct tblproduct)
 {
     if (tblproduct != null && tblproduct.ID != null && !tblproduct.ID.Equals(Guid.Empty))
     {
         var query = _dataContext.tblProducts.Where("ID.ToString()=@0", tblproduct.ID.ToString());
         if (query != null && query.ToList().Count > 0)
         {
             query.First().PriceEN = tblproduct.PriceEN;
             query.First().PriceVN = tblproduct.PriceVN;
             query.First().ProductNameEN = tblproduct.ProductNameEN;
             query.First().ProductNameVN = tblproduct.ProductNameVN;
             query.First().ProductNo = tblproduct.ProductNo;
             //query.First().tblCategory= tblproduct.tblCategory;
             query.First().UpdatedBy = tblproduct.UpdatedBy;
             query.First().UpdatedDate = DateTime.Now;
             query.First().CreatedBy = tblproduct.CreatedBy;
             query.First().CategoryID = tblproduct.CategoryID;
             query.First().Description = tblproduct.Description;
             query.First().Image = tblproduct.Image;
             query.First().StoreStatus = tblproduct.StoreStatus;
             query.First().Promoted = tblproduct.Promoted;
             query.First().WarrantyTime = tblproduct.WarrantyTime;
             query.First().Property = tblproduct.Property;
             _dataContext.SubmitChanges();
         }
     }
 }
        public void InsertProduct(tblProduct tblproduct)
        {
            if (tblproduct != null && tblproduct.ID != null && !tblproduct.ID.Equals(Guid.Empty))
            {

                tblproduct.CreatedDate = DateTime.Now;
                _dataContext.tblProducts.InsertOnSubmit(tblproduct);
                _dataContext.SubmitChanges();
            }
        }