Ejemplo n.º 1
0
        //ViewGroup
        public ActionResult ViewGroup(string titleidgroup, int?page)
        {
            GroupProduct gp = db.GroupProducts.Where(x => x.SeoUrl == titleidgroup && x.IsDisable == false).FirstOrDefault();

            if (gp == null)
            {
                return(RedirectToAction("HttpError404", "Error"));
            }

            ViewBag.GroupProduct = gp;
            int            currentPageIndex    = page.HasValue ? page.Value - 1 : 0;
            List <Product> ListProduct         = new List <Product>();
            List <Product> ListProductOfParent = db.Products.Include(x => x.GroupProduct).Where(x => x.GroupProduct.GroupProductId == gp.GroupProductId).OrderByDescending(x => x.Order).ToList();

            //nếu là nhóm cha thì lấy sản phẩm nhóm con và của chính nó(nếu có)
            if (gp.IdRoot == null)
            {
                ListProduct = db.Products.Include(x => x.GroupProduct).Where(x => x.GroupProduct.GroupProductParrent.GroupProductId == gp.GroupProductId).OrderByDescending(x => x.Order).ToList();
            }

            ListProduct.AddRange(ListProductOfParent);

            if (ListProduct == null)
            {
                ListProduct = new List <Product>();
            }

            return(View(ListProduct.ToPagedList(currentPageIndex, 12)));
        }
Ejemplo n.º 2
0
        public ProductsListModel()
        {
            List <GroupProduct> groups;

            try
            {
                productsModel    = new List <Product>();
                productsAllModel = new List <ProductsModel>();
                productsOther    = new ProductsModel();
                using (var entity = new dehunEntities())
                {
                    ProductsModel model;
                    GroupProduct  group = entity.GroupProducts.Where(r => r.Priority == 1 && r.Active == 1).FirstOrDefault();
                    productsModel = entity.Products.Where(r => r.Active == 1 && r.IsHot == 1 && !string.IsNullOrEmpty(r.Image1)).ToList();

                    groups = entity.GroupProducts.Where(r => r.Active == 1).ToList();
                    foreach (var item in groups)
                    {
                        model          = new ProductsModel();
                        model.group    = item;
                        model.products = entity.Products.Where(r => r.Active == 1 && r.GroupId == item.Id && !string.IsNullOrEmpty(r.Image1)).ToList();
                        if (model.products.Count > 0)
                        {
                            productsAllModel.Add(model);
                        }
                    }
                    productsOther.group    = group;
                    productsOther.products = entity.Products.Where(r => r.GroupId == group.Id && r.Active == 1 && !string.IsNullOrEmpty(r.Image1)).ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        private void LoadDropDownListPageLink()
        {
            ddlLink.Items.Clear();
            ddlLink.Items.Add(new ListItem("■Trang chủ", "/"));
            GroupProduct        obj   = new GroupProduct();
            List <GroupProduct> lstGr = obj.SelectByTop("", "Active=1", "Level,Ord");

            //ddlLink.Items.Add(new ListItem("■Dịch vụ", "#"));
            for (int i = 0; i < lstGr.Count; i++)
            {
                ddlLink.Items.Add(new ListItem(StringClass.ShowNameLevel("■" + lstGr[i].Name, lstGr[i].Level), "/" + Consts.SAN_PHAM + "/" + lstGr[i].Id + "/" + StringClass.NameToTag(lstGr[i].Name)));
                //List<Product> pro = Product.SelectByTop("", "Active=1 AND GroupId=" + lstGr[i].Id, "Ord");
                //for (int j = 0; j < pro.Count; j++)
                //{
                //    ddlLink.Items.Add(new ListItem(StringClass.ShowNameLevel(pro[j].Name, lstGr[i].Level + "00000"), StringClass.GeneralDetailUrl(Consts.SAN_PHAM, pro[j].GroupName, pro[j].Id.ToString(), pro[j].Name)));
                //}
            }
            List <GroupNews> listN = GroupNews.SelectByTop("", "Active=1", "Level, Ord");

            //ddlLink.Items.Add(new ListItem("■Tin tức", "#"));
            //         if (listN.Count > 0)
            //         {
            //             for (int i = 0; i < listN.Count; i++)
            //             {
            //		ddlLink.Items.Add(new ListItem(StringClass.ShowNameLevel(listN[i].Name, listN[i].Level + "00000"), "/" + Consts.TIN_TUC + "/" + listN[i].Id + "/" + StringClass.NameToTag(listN[i].Name)));
            //             }
            //         }
            ddlLink.Items.Add(new ListItem("■Liên hệ", "/lien-he"));
            ddlLink.DataBind();
        }
        public async Task <string> Create(GroupProduct item)
        {
            var result = _mapper.Map <GroupProductDB>(item);

            var modelBoard = (await _dataBase.Find <GroupBoardDB>(
                                  x => x.Id == result.GroupBoardId).ConfigureAwait(false)).FirstOrDefault();

            if (modelBoard == null)
            {
                throw new ValidationException("Board not found");
            }

            var modelProduct = await _dataBase.Find <GroupProductDB>(x => x.ProductId == result.ProductId).ConfigureAwait(false);

            if (modelProduct.Any())
            {
                throw new ValidationException("Product already added");
            }

            result.Id       = Guid.NewGuid().ToString();
            result.Modified = DateTime.UtcNow;

            _dataBase.Create(result);
            await _dataBase.Save();

            return(result.Id);
        }
Ejemplo n.º 5
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    GroupProduct objGr = new GroupProduct();
                    objGr.Name        = txtName.Value.Trim();
                    objGr.Image       = txtImage.Value.Trim();
                    objGr.Priority    = 0;
                    objGr.Position    = 0;
                    objGr.Keywords    = txtKeywords.Value.Trim();
                    objGr.Description = txtDescription.Value.Trim();
                    objGr.Items       = 0;
                    objGr.Level       = level + "00000";
                    objGr.Ord         = txtOrd.Value.Trim() != "" ? int.Parse(txtOrd.Value.Trim()) : 1;
                    objGr.Active      = chkActive.Checked ? 1 : 0;

                    if (id != string.Empty)
                    {
                        objGr.Id = int.Parse(id);
                        objGr.Update();
                    }
                    else
                    {
                        objGr.Insert();
                    }
                    Response.Redirect("GroupProductList.aspx", false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Details(int id, [Bind("Id,Name")] GroupProduct model)
        {
            if (ModelState.IsValid)
            {
                if (GroupProductExists(id) == false)
                {
                    model.CreatedDate = DateTime.Now;
                    model.UserId      = _userManager.GetUserId(HttpContext.User);
                    _context.Add(model);
                    await _context.SaveChangesAsync();
                }
                else
                {
                    var group = await _context.GroupProducts.FindAsync(id);

                    group.Name         = model.Name;
                    group.ModifiedDate = DateTime.Now;
                    group.UserId       = _userManager.GetUserId(HttpContext.User);
                    _context.Update(group);
                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            id    = BizUtils.GetQueryString("Id", Request);
            level = BizUtils.GetQueryString("Level", Request);
            if (!IsPostBack)
            {
                if (id != string.Empty)
                {
                    btnUpdate_T.Visible = true;
                    btnUpdate_B.Visible = true;
                    btnAdd_B.Visible    = false;
                    btnAdd_T.Visible    = false;

                    GroupProduct objGr = new GroupProduct();
                    objGr.Id             = int.Parse(id);
                    objGr                = objGr.SelectById();
                    txtName.Value        = objGr.Name;
                    txtImage.Value       = objGr.Image;
                    imgImage.ImageUrl    = objGr.Image;
                    txtKeywords.Value    = objGr.Keywords;
                    txtDescription.Value = objGr.Description;
                    //chkPriority.Checked = objGr.Priority == 1;
                    //chkPosition.Checked = objGr.Position == 1;
                    txtOrd.Value      = objGr.Ord.ToString();
                    chkActive.Checked = objGr.Active == 1;
                    lblTitle.Text     = "Cập nhật nhóm sản phẩm";
                }
                else
                {
                    txtOrd.Value = Config.GetMaxOrd("GroupProduct", level, true);
                }
            }
        }
Ejemplo n.º 8
0
        public ActionResult GroupProductAddSubot(FormCollection collection, GroupProduct catego)
        {
            if (Request.Cookies["Username"] != null)
            {
                // Lấy dữ liệu từ view
                int    parentId = 0;
                string level    = "00000";
                if (collection["GroupProduct"] != "")
                {
                    parentId = Int32.Parse(collection["GroupProduct"]);
                    string parentLevel = db.GroupProducts.Where(g => g.Id == parentId).SingleOrDefault().Level;
                    level = parentLevel + "00000";
                }
                catego.Level       = level;
                catego.ParentId    = parentId;
                catego.Name        = collection["Name"];
                catego.Title       = collection["Title"];
                catego.Description = collection["Description"];
                catego.Keyword     = collection["Keyword"];
                catego.Ord         = Convert.ToInt32(collection["Ord"]);
                catego.Tag         = StringClass.NameToTag(collection["Name"]);
                catego.Priority    = (collection["Priority"] == "false") ? false : true;
                catego.Index       = (collection["Index"] == "false") ? false : true;
                catego.Active      = (collection["Active"] == "false") ? false : true;


                db.Entry(catego).State = EntityState.Added;
                db.SaveChanges();
                return(RedirectToAction("GroupProductIndexot"));
            }
            else
            {
                return(Redirect("/Admins/admins"));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            GroupProduct groupProduct = db.GroupProducts.Find(id);

            Delete_Recur(db, groupProduct);
            return(RedirectToAction("Index"));
        }
        private void Delete_Recur(DBFrontEnd db, GroupProduct gp)
        {
            List <GroupProduct> ListGroupProduct = gp.GroupProductChildrens.ToList();

            if (ListGroupProduct != null)
            {
                foreach (var i in ListGroupProduct)
                {
                    Delete_Recur(db, i);
                }
            }

            List <Product> ListProduct = gp.Products.ToList();

            if (ListProduct != null)
            {
                foreach (var i in ListProduct)
                {
                    db.Products.Remove(i);
                }
                db.SaveChanges();
            }

            db.GroupProducts.Remove(gp);
            db.SaveChanges();
        }
Ejemplo n.º 11
0
 public async Task <int> AddOrUpdateGroupProduct(GroupProduct groupProduct)
 {
     using (DatanetCMSWebEntities context = new DatanetCMSWebEntities())
     {
         context.GroupProducts.AddOrUpdate(groupProduct);
         return(await context.SaveChangesAsync());
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            GroupProduct groupProduct = db.GroupProducts.Find(id);

            db.GroupProducts.Remove(groupProduct);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                id = BizUtils.GetQueryString("Id", Request);
                if (!IsPostBack)
                {
                    GroupProduct        objGr = new GroupProduct();
                    List <GroupProduct> lstGr = objGr.SelectByTop("", "Active = 1 AND Position = 1", "Level, Ord");
                    ddlGroup.Items.Clear();
                    ddlGroup.Items.Add(new ListItem("--Chọn nhóm dịch vụ--", ""));
                    for (int i = 0; i < lstGr.Count; i++)
                    {
                        objGr = lstGr[i];
                        ddlGroup.Items.Add(new ListItem(StringClass.ShowNameLevel(objGr.Name, objGr.Level), objGr.Id.ToString()));
                    }
                    ddlGroup.DataBind();

                    if (id != string.Empty)
                    {
                        btnUpdate_T.Visible = true;
                        btnUpdate_B.Visible = true;
                        btnAdd_B.Visible    = false;
                        btnAdd_T.Visible    = false;

                        Product objPr = new Product();
                        objPr.Id             = int.Parse(id);
                        objPr                = objPr.SelectById();
                        txtName.Value        = objPr.Name;
                        txtImage1.Value      = objPr.Image1;
                        imgImage1.ImageUrl   = objPr.Image1;
                        txtImage2.Value      = objPr.Image2;
                        imgImage2.ImageUrl   = objPr.Image2;
                        txtImage3.Value      = objPr.Image3;
                        imgImage3.ImageUrl   = objPr.Image3;
                        txtImage4.Value      = objPr.Image4;
                        imgImage4.ImageUrl   = objPr.Image4;
                        txtContent.Value     = objPr.Content;
                        ddlGroup.Value       = objPr.GroupId.ToString();
                        fckDetail.Value      = objPr.Detail;
                        txtKeywords.Value    = objPr.Keywords;
                        txtDescription.Value = objPr.Description;
                        chkPopular.Checked   = objPr.IsPopular == 1;
                        txtOrd.Value         = objPr.Ord.ToString();
                        chkActive.Checked    = objPr.Active == 1;
                        lblTitle.Text        = "Cập nhật dịch vụ";
                    }
                    else
                    {
                        txtOrd.Value = Config.GetMaxOrd("Product", "");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 14
0
 public async Task <int> DeleteGroupProduct(GroupProduct groupProduct)
 {
     using (DatanetCMSWebEntities context = new DatanetCMSWebEntities())
     {
         groupProduct.ExpireTime = DateTime.UtcNow;
         context.GroupProducts.AddOrUpdate(groupProduct);
         return(await context.SaveChangesAsync());
     }
 }
Ejemplo n.º 15
0
 public ActionResult Edit([Bind(Include = "Id,Name,Unit,Price")] GroupProduct groupProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groupProduct));
 }
Ejemplo n.º 16
0
 public ActionResult Edit([Bind(Include = "id,name,conntent,image,order,status")] GroupProduct groupProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(groupProduct));
 }
Ejemplo n.º 17
0
        public static int GetLevel(this GroupProduct group, int level = 0)
        {
            if (group.ParentGroupID == null || group.ParentGroupID == 0)
            {
                return(level);
            }
            level++;
            var category = group.GroupProduct1;

            return(category.GetLevel(level));
        }
Ejemplo n.º 18
0
        public ActionResult Create([Bind(Include = "Id,Name,Unit,Price")] GroupProduct groupProduct)
        {
            if (ModelState.IsValid)
            {
                db.GroupProducts.Add(groupProduct);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(groupProduct));
        }
        public async Task <IActionResult> Create(GroupProduct groupProduct)
        {
            if (ModelState.IsValid)
            {
                _db.Add(groupProduct);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(groupProduct));
        }
Ejemplo n.º 20
0
        public ActionResult Create([Bind(Include = "id,name,conntent,image,order,status")] GroupProduct groupProduct)
        {
            if (ModelState.IsValid)
            {
                db.GroupProducts.Add(groupProduct);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(groupProduct));
        }
        // GET: Admin/GroupProduct/Edit/5
        public async Task <IActionResult> Details(int?id)
        {
            var model = await _context.GroupProducts.SingleOrDefaultAsync(m => m.Id == id);

            if (model == null)
            {
                model = new GroupProduct();
                return(View(model));
            }

            return(View(model));
        }
Ejemplo n.º 22
0
        private static void SaveFile()
        {
            var elements = new XElement("Palettes");

            _document = new XDocument(elements);

            foreach (var group in GroupProducts)
            {
                elements.Add(GroupProduct.ToXElement(group));
            }

            _document.Save(Path);
        }
Ejemplo n.º 23
0
        private void BtnAdd1Click(object sender, RoutedEventArgs e)
        {
            var window = new TextWindow();

            if (window.ShowDialog() == true)
            {
                var group = new GroupProduct(RepositoryGroupProduct.GroupProducts.Count + 1, window.NameText);
                RepositoryGroupProduct.Add(group);

                DataGridGroups.ItemsSource = null;
                DataGridGroups.ItemsSource = RepositoryGroupProduct.GroupProducts;
            }
        }
Ejemplo n.º 24
0
        private static void LoadFile()
        {
            if (File.Exists(Path))
            {
                GroupProducts.Clear();
                _document = XDocument.Load(Path);

                foreach (var el in _document.GetXElements("Palettes", "Palette"))
                {
                    GroupProducts.Add(GroupProduct.FromXElement(el));
                }
            }
        }
        public void TestCaseSetup()
        {
            _groupProductDB = new GroupProductDB
            {
                Id           = "00000000-0000-0000-0000-000000000004",
                GroupBoardId = "00000000-0000-0000-0000-000000000003",
                Information  = "Information",
                ProductId    = "2"
            };
            _groupProduct = new GroupProduct
            {
                Id           = "00000000-0000-0000-0000-000000000004",
                GroupBoardId = "00000000-0000-0000-0000-000000000003",
                Information  = "Information",
                ProductId    = "2"
            };
            _groupBoardDB = new GroupBoardDB
            {
                Id            = "00000000-0000-0000-0000-000000000003",
                CreatorId     = "2",
                Information   = "Some product",
                Name          = "Best",
                Created       = DateTime.UtcNow,
                Deleted       = null,
                IsNotDeleted  = true,
                Modified      = DateTime.UtcNow,
                GroupId       = "00000000-0000-0000-0000-000000000001",
                GroupProducts = null
            };
            _groupUserDB = new GroupUserDB
            {
                GroupId             = "00000000-0000-0000-0000-000000000001",
                RightToCreateBoards = true
            };
            _groupRepositoryMock = new Mock <IGroupRepository>();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new GroupProfile());
                cfg.AddProfile(new GroupBoardProfile());
                cfg.AddProfile(new GroupProductProfile());
                cfg.AddProfile(new GroupUserProfile());
                cfg.AddProfile(new GroupCommentProfile());
            });

            _mapper = (new Mapper(config)).DefaultContext.Mapper;
            _groupProductService = new GroupProductService(_groupRepositoryMock.Object, _mapper);
            _selectedBoardList   = new List <GroupBoardDB>();
            _selectedUserList    = new List <GroupUserDB>();
            _selectedProductList = new List <GroupProductDB>();
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupProduct groupProduct = db.GroupProducts.Find(id);

            if (groupProduct == null)
            {
                return(HttpNotFound());
            }
            return(View(groupProduct));
        }
        public ActionResult Edit([Bind(Include = "GroupProductId,GroupName,SeoUrl,Order,IsDisable,IsShowOnTop,ImgUrl,IdRoot")] GroupProduct groupProduct)
        {
            List <GroupProduct> ListGroupProduct = db.GroupProducts.Where(x => x.CountNode < 2).OrderBy(x => x.GroupName).ToList();

            ListGroupProduct.Insert(0, new GroupProduct()
            {
                GroupName = "Gốc"
            });

            if (ModelState.IsValid)
            {
                if (groupProduct.SeoUrl == null)
                {
                    groupProduct.SeoUrl = DreamCMS.FuncHelp.DHelp.SEOurl(groupProduct.GroupName);
                }
                if (db.GroupProducts.Where(x => x.SeoUrl == groupProduct.SeoUrl && x.GroupProductId != groupProduct.GroupProductId).FirstOrDefault() != null)
                {
                    ViewBag.IsValidName = "Tên nhóm đã được sử dụng!!!";
                    ViewBag.IdRoot      = new SelectList(ListGroupProduct, "GroupProductId", "GroupName", groupProduct.IdRoot);
                    return(View(groupProduct));
                }

                if (groupProduct.IdRoot == 0)
                {
                    groupProduct.IdRoot = null; groupProduct.CountNode = 0;
                }
                else
                {
                    GroupProduct gpRoot = db.GroupProducts.Where(x => x.GroupProductId == groupProduct.IdRoot).FirstOrDefault();
                    groupProduct.CountNode = gpRoot.CountNode + 1;
                }

                GroupProduct gp = db.GroupProducts.Where(x => x.GroupProductId == groupProduct.GroupProductId).FirstOrDefault();
                gp.GroupName   = groupProduct.GroupName;
                gp.SeoUrl      = groupProduct.SeoUrl;
                gp.CountNode   = groupProduct.CountNode;
                gp.Order       = groupProduct.Order;
                gp.IsDisable   = groupProduct.IsDisable;
                gp.ImgUrl      = groupProduct.ImgUrl;
                gp.IdRoot      = groupProduct.IdRoot;
                gp.IsShowOnTop = groupProduct.IsShowOnTop;
                //db.Entry(groupProduct).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IdRoot = new SelectList(ListGroupProduct, "GroupProductId", "GroupName", groupProduct.IdRoot);
            return(View(groupProduct));
        }
Ejemplo n.º 28
0
        public ActionResult Delete(int?id, bool confirm = false)
        {
            dynamic result = new ExpandoObject();

            if (id == null)
            {
                result.status  = "error";
                result.title   = "Lỗi";
                result.message = "Không có mã id nhóm";
                return(Content(JsonConvert.SerializeObject(result), "application/json"));
            }

            var group = Repository.GroupProduct.FindById(id);

            if (group == null)
            {
                result.status  = "error";
                result.title   = "Lỗi";
                result.message = "Nhóm này không tồn tại trong hệ thống";
                return(Content(JsonConvert.SerializeObject(result), "application/json"));
            }
            if (group.Products.Count > 0 && !confirm)
            {
                result.status  = "warning";
                result.title   = "Cảnh báo";
                result.message = "Nhóm này chứa nhiều sản phẩm, khi xóa sẽ mất hết sản phẩm, hãy cân nhắc trước khi xóa";
                return(Content(JsonConvert.SerializeObject(result), "application/json"));
            }
            GroupProduct _item = Repository.GroupProduct.FindById(id);

            if (_item.Products.Count > 0)
            {
                _item.Products.ToList().ForEach(a => Repository.Product.Delete(a.ProductID));
            }
            Repository.GroupProduct.Delete(id);
            Repository.SaveChanges();
            if (Repository.GroupProduct.FetchAll().Any(g => g.GroupID == id))
            {
                result.status  = "error";
                result.title   = "Lỗi";
                result.message = "Đã có lỗi xảy ra, không thể xóa được";
                return(Content(JsonConvert.SerializeObject(result), "application/json"));
            }
            result.status  = "success";
            result.title   = "Thành công";
            result.message = "Chúc mừng bạn đã xóa thành công";
            return(Content(JsonConvert.SerializeObject(result), "application/json"));
        }
Ejemplo n.º 29
0
            private void DoAddGroup()
            {
                Preamp preamp = null;

                if (iServiceProduct.Attributes.Contains("Volume"))
                {
                    preamp = new Preamp("Preamp", iDevice);
                }

                iGroup = new GroupProduct(iRoom, iName, iStandby, preamp, this);

                if (iStack.EventGroupAdded != null)
                {
                    iStack.EventGroupAdded(iStack, new EventArgsGroup(iGroup));
                }
            }
        public async Task <IActionResult> Edit(int id, GroupProduct groupProduct)
        {
            if (id != groupProduct.GroupProductID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _db.Update(groupProduct);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(groupProduct));
        }