Exemplo n.º 1
0
        public FileResult ExportExcel(ThemTinTucModel obj)
        {
            string         tacvu = obj.Content;
            ShopDataContex db    = new ShopDataContex();
            DataTable      dt    = new DataTable("Grid");

            dt.Columns.AddRange(new DataColumn[15]
            {
                new DataColumn("ID"),
                new DataColumn("ID2"),
                new DataColumn("Item title"),
                new DataColumn("Final URL"),
                new DataColumn("Image URL"),
                new DataColumn("Item subtitle"),
                new DataColumn("Item description"),
                new DataColumn("Item category"),
                new DataColumn("Price"),
                new DataColumn("Sale price"),
                new DataColumn("Contextual keywords"),
                new DataColumn("Item address"),
                new DataColumn("Tracking template"),
                new DataColumn("Custom parameter"),
                new DataColumn("Action")
            });

            var Menus = db.Menu.Where(o => o.idControl == 11 && o.ok && o.HasValue && o.HasOnHand && o.DungSai && o.TenNgan != null && o.MoTaNgan != null).OrderByDescending(o => o.sDateOk).ToList();

            foreach (var product in Menus)
            {
                string ID                 = "BG" + product.id_;
                string ID2                = "";
                string Itemtitle          = product.TenNgan;
                string FinalURL           = "https://beautygarden.vn/" + product.Link + ".html";
                string ImageURL           = "https://beautygarden.vn/Upload/Files/" + product.Img;
                string Itemsubtitle       = "beautygarden.vn";
                string Itemdescription    = product.MoTaNgan;
                string Itemcategory       = "";
                string Price              = product.PricePro + " VND";
                string Saleprice          = "";
                string Contextualkeywords = "";
                string Itemaddress        = "";
                string Trackingtemplate   = "";
                string Customparameter    = "";
                string Action             = tacvu;

                dt.Rows.Add(ID, ID2, Itemtitle, FinalURL, ImageURL, Itemsubtitle, Itemdescription, Itemcategory, Price, Saleprice, Contextualkeywords,
                            Itemaddress, Trackingtemplate, Customparameter, Action);
            }

            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt);
                using (MemoryStream stream = new MemoryStream())
                {
                    wb.SaveAs(stream);
                    return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "CSVgoogle.xlsx"));
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult SaveEdit(ThemTinTucModel model)
        {
            #region update tin tuc

            DetailMenu dlcu = _detailMenuRepository.GetById(model.id_);
            dlcu.id_       = model.id_;
            dlcu.Name      = model.Name;
            dlcu.Img       = (model.Img).Replace("/files/", "");
            dlcu.Link      = model.Link;
            dlcu.id_       = model.id_;
            dlcu.Note      = model.Note;
            dlcu.sPosition = model.sPosition;
            dlcu.sDate     = DateTime.Now;
            dlcu.sDateOk   = DateTime.Now;
            //dlcu.Content =  ChangeImageSEO(model.Content, model.Name, ConvertFont(model.Name));
            dlcu.Content        = model.Content;
            dlcu.SEODescription = model.SEODescription;
            dlcu.SEOtitle       = model.SEOtitle;
            dlcu.CodeName       = ConvertFont(model.Name).Replace("-", " ");
            dlcu.IdSalePage     = model.IdSalePage;
            dlcu.NguoiTao       = User.Identity.Name;
            _detailMenuRepository.Update(dlcu);
            _unitOfWork.Commit();

            #endregion

            if (model.mySingleField != null)
            {
                #region danh sach tag
                string[] separators = { "," };
                var      taglist    = model.mySingleField.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                //check null: nếu tồn tại thêm mới bình thường
                if (taglist.Any())
                {
                    foreach (var tag in taglist)
                    {
                        //check trung
                        int checktrung = _tagTinTucRepository.GetTagNamebyIdmenu(model.id_, tag.Trim());
                        if (checktrung == 0)
                        {
                            TagTinTuc _tag = new TagTinTuc()
                            {
                                NgayTao = DateTime.Now,
                                IdMenu  = dlcu.id_,
                                TenTag  = tag.Trim(),
                                Link    = ConvertFont(tag.Trim()),
                                Code    = RejectMarks(tag.Trim())
                            };
                            _tagTinTucRepository.Add(_tag);
                            _unitOfWork.Commit();
                        }
                    }
                }
                #endregion
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Addnew(ThemTinTucModel model)
        {
            if (ModelState.IsValid)
            {
                DetailMenu tintuc = new DetailMenu()
                {
                    sDate          = DateTime.Now,
                    Name           = RejectMarks(model.Name),
                    Note           = model.Note,
                    Img            = (model.Img).Replace("/files/", ""),
                    Content        = model.Content,
                    id_Menu        = 20,
                    Link           = ConvertFont(model.Name),
                    idUser         = 15,
                    idUserOk       = 15,
                    sDateOk        = DateTime.Now,
                    ok             = true,
                    Ma_Hang        = "",
                    NameAdwords    = "",
                    Number         = 0,
                    ShowMenu       = true,
                    ShowIconHot    = false,
                    ShowKhuyenMai  = false,
                    ShowIconNew    = false,
                    TinhTrangSP    = false,
                    SEODescription = model.SEODescription,
                    SEOtitle       = model.SEOtitle
                };

                _detailMenuRepository.Add(tintuc);
                _unitOfWork.Commit();
            }
            else
            {
                return(View("Create", model));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Addnew(ThemTinTucModel model)
        {
            //if (ModelState.IsValid)
            //{
            #region them moi tin tuc

            DetailMenu tintuc = new DetailMenu()
            {
                sDate   = DateTime.Now,
                Name    = RejectMarks(model.Name),
                Note    = model.Note,
                Img     = (model.Img).Replace("/files/", ""),
                Content = ChangeImageSEO(model.Content, model.Name, ConvertFont(model.Name)),
                //Content = model.Content,
                id_Menu        = 20,
                Link           = ConvertFont(model.Name),
                idUser         = 15,
                idUserOk       = 15,
                sDateOk        = DateTime.Now,
                ok             = true,
                Ma_Hang        = "",
                NameAdwords    = "",
                Number         = 0,
                ShowMenu       = true,
                ShowIconHot    = false,
                ShowKhuyenMai  = true,
                ShowIconNew    = false,
                TinhTrangSP    = false,
                sPosition      = model.sPosition,
                SEODescription = model.SEODescription,
                SEOtitle       = model.SEOtitle,
                CodeName       = ConvertFont(model.Name).Replace("-", " "),
                IdSalePage     = model.IdSalePage,
                NguoiTao       = User.Identity.Name
            };

            _detailMenuRepository.Add(tintuc);
            _unitOfWork.Commit();

            #endregion

            if (model.mySingleField != null)
            {
                #region them moi tag

                string[] separators = { "," };
                var      taglist    = model.mySingleField.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                //check null: nếu tồn tại thêm mới bình thường
                if (taglist.Any())
                {
                    foreach (var tag in taglist)
                    {
                        TagTinTuc _tag = new TagTinTuc()
                        {
                            NgayTao = DateTime.Now,
                            IdMenu  = tintuc.id_,                 // id cua tin moi vua them
                            TenTag  = tag.Trim(),
                            Link    = ConvertFont(tag.Trim()),
                            Code    = RejectMarks(tag.Trim())
                        };
                        _tagTinTucRepository.Add(_tag);
                        _unitOfWork.Commit();
                    }
                }
                #endregion
            }
            //}
            //else
            //{
            //    return View("Create", model);
            //}
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public void ExportToCSVAdsDynamicGoogle(ThemTinTucModel obj)
        {
            try
            {
                string tacvu = obj.Content;
                tacvu = string.IsNullOrEmpty(tacvu) ? "" : tacvu;
                StringWriter sw = new StringWriter();
                sw.WriteLine("ID\t" +
                             "ID2\t" +
                             "Item title\t" +
                             "Final URL\t" +
                             "Image URL\t" +
                             "Item subtitle\t" +
                             "Item description\t" +
                             "Item category\t" +
                             "Price\t" +
                             "Sale price\t" +
                             "Contextual keywords\t" +
                             "Item address\t" +
                             "Tracking template\t" +
                             "Custom parameter\t" +
                             tacvu);

                Response.ClearContent();
                Response.AddHeader("content-disposition", "attachment;filename=CSVAdsDynamicGoogle.csv");
                Response.ContentType = "application/octet-stream";

                ShopDataContex db    = new ShopDataContex();
                var            Menus = db.Menu.Where(o => o.idControl == 11 && o.ok && o.HasValue && o.HasOnHand && o.DungSai && o.TenNgan != null && o.MoTaNgan != null).OrderByDescending(o => o.sDateOk).ToList();

                foreach (var menu in Menus)
                {
                    sw.WriteLine(string.Format("{0}\t" +
                                               "{1}\t" +
                                               "{2}\t" +
                                               "{3}\t" +
                                               "{4}\t" +
                                               "{5}\t" +
                                               "{6}\t" +
                                               "{7}\t" +
                                               "{8}\t" +
                                               "{9}\t" +
                                               "{10}\t" +
                                               "{11}\t" +
                                               "{12}\t" +
                                               "{13}\t" +
                                               "{14}",
                                               "BG" + menu.id_,
                                               "",
                                               CheckString25Char(menu.TenNgan == null ? menu.NameProductLong : menu.TenNgan),
                                               "https://beautygarden.vn/" + menu.Link + ".html",
                                               "https://beautygarden.vn/Upload/Files/" + menu.Img,
                                               "beautygarden.vn",
                                               CheckString25Char(menu.MoTaNgan == null ? "Mỹ Phẩm Chính Hãng" : menu.MoTaNgan),
                                               GetTenDanhMuc(menu.id_),
                                               menu.PricePro + " VND",
                                               "",
                                               "",
                                               "",
                                               "",
                                               "",
                                               tacvu
                                               ));
                }
                Response.Write(sw.ToString());
                Response.End();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }