public ActionResult Add(string key) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); var model = new Shop_Product(); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } UpdateModel(model); model.IsDelete = false; model.IsShow = false; model.DateCreated = DateTime.Now; model.NameAscii = FDIUtils.Slug(model.Name); model.Quantity = 0; model.QuantityOut = 0; _da.Add(model); _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu Chưa được thêm mới."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public void updatenameasi() { var query = (from c in FDIDB.Categories select c).ToList(); foreach (var itemCategory in query) { itemCategory.Slug = FDIUtils.Slug(FDIUtils.NewUnicodeToAscii(itemCategory.Name)); } Save(); }
public ActionResult Add(string key, string code) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); var model = new Shop_Product_Detail(); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } UpdateModel(model); var CodeSku = Request["CodeSku"]; model.IsDelete = false; var lstPicture = Request["Value_DefaultImages"]; if (!string.IsNullOrEmpty(lstPicture)) { var lstInt = FDIUtils.StringToListInt(lstPicture); model.PictureID = lstInt.FirstOrDefault(); } model.Name = HttpUtility.UrlDecode(model.Name); model.NameAscii = FDIUtils.Slug(model.Name); model.Code = HttpUtility.UrlDecode(CodeSku); _detailDa.Add(model); _detailDa.Save(); var CreateBy = Request["CreateBy"]; //var Percent = Request["Percent"]; var product = new Shop_Product { ProductDetailID = model.ID, CodeSku = model.Code, Quantity = model.QuantityDay, CreateBy = CreateBy, CreateDate = DateTime.Now.TotalSeconds(), IsShow = true, IsDelete = false, }; _da.Add(product); _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu Chưa được thêm mới."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public List <Select2Model> GetAllListSelect2(string key, int page, ref int total) { var keyword = FDIUtils.Slug(key); var query = from c in FDIDB.Shop_Product where c.IsDelete == false && c.NameAscii.Contains(keyword) && c.IsShow == true orderby c.ID descending select new Select2Model() { text = c.Name, id = c.Name, }; total = query.Count(); query = query.Skip((page - 1) * 10).Take(10); return(query.ToList()); }
//public ActionResult AjaxFormFiles() //{ // var model = _categoryApi.GetChildByParentId(false); // ViewBag.Action = DoAction; // return View(model); //} public ActionResult UploadFiles() { //string[] lst = new string[] { "jpg", "png" }; var item = new FileObj(); var urlFolder = ConfigData.TempFolder; if (!Directory.Exists(urlFolder)) { Directory.CreateDirectory(urlFolder); } foreach (string file in Request.Files) { var hpf = Request.Files[file]; var fileNameRoot = hpf != null ? hpf.FileName : string.Empty; if (hpf != null && hpf.ContentLength == 0) { continue; } if (hpf != null) { if (fileNameRoot.Length > 1) { var fileLocal = fileNameRoot.Split('.'); var name = ""; var index = fileLocal.Length - 2; for (var i = 0; i <= index; i++) { name = name.Trim() + " " + fileLocal[i]; } _fileName = FDIUtils.Slug(name) + "-" + DateTime.Now.ToString("MMddHHmmss") + "." + fileLocal[fileLocal.Length - 1]; var savedFileName = Path.Combine((urlFolder), Path.GetFileName(_fileName)); hpf.SaveAs(savedFileName); item = new FileObj { Name = _fileName, NameRoot = name, Forder = ConfigData.Temp, Icon = "/Images/Icons/file/" + fileLocal[1] + ".png", Error = false }; } } } return(Json(item)); }
public ActionResult UploadFiles() { //string[] lst = new string[] { "jpg", "png" }; var item = new FileObj(); var urlFolder = ConfigData.TempFolder; if (!Directory.Exists(urlFolder)) { Directory.CreateDirectory(urlFolder); } foreach (string file in Request.Files) { var hpf = Request.Files[file]; var fileNameRoot = hpf != null ? hpf.FileName : string.Empty; if (hpf != null && hpf.ContentLength == 0) { continue; } if (hpf != null) { if (fileNameRoot.Length > 1) { var fileLocal = fileNameRoot.Split('.'); //if (!lst.Contains(fileLocal[1].ToLower())) //{ // item.Error = true; // continue; //} var fileName = FDIUtils.Slug(fileLocal[0]) + "-" + DateTime.Now.ToString("MMddHHmmss") + "." + fileLocal[1]; var savedFileName = Path.Combine((urlFolder), Path.GetFileName(fileName)); hpf.SaveAs(savedFileName); item = new FileObj { Name = fileName, NameRoot = fileLocal[0], Forder = ConfigData.Temp, Icon = "/Images/Icons/file/" + fileLocal[1] + ".png", Error = false }; } } } return(Json(item)); }
public List <SuggestionsProduct> GetListAuto(string keword, int showLimit, int type = 1) { var name = FDIUtils.Slug(keword); var query = FDIDB.AutoSelectProduct(name, showLimit).Select(c => new SuggestionsProduct { ID = c.ID, UrlImg = c.UrlImg ?? "/Content/Admin/images/auto-default.jpg", name = "", code = c.BarCode ?? "", value = c.BarCode ?? "", data = "<span class='maskPrice'>" + c.PriceNew + "</span> đ", title = c.Name, pricenew = c.PriceNew, Type = type }); return(query.ToList()); }
public List <ProductAppIG4Item> GetCategoryForMap(string name, double minKm, double maxKm, int minPrice, int maxPrice, int categoryId, double Latitude, double Longitude) { if (!string.IsNullOrEmpty(name)) { name = String.Join(",", FDIUtils.Slug(FDIUtils.NewUnicodeToAscii(name)).Split('_').ToList()); } var query = from p in FDIDB.ShopMap(name, maxKm, minKm, categoryId, Latitude, Longitude, minPrice, maxPrice) select new ProductAppIG4Item { Longitude = p.Longitude ?? 0, Latitude = p.Latitude ?? 0, CustomerId = p.CustomerId, IsPrestige = p.IsPrestige, UrlPicture = p.UrlIcon, Sort = p.sortut }; return(query.ToList()); }
private void UploadDocument(string fileNameLocal, int idDocument) { if (!string.IsNullOrEmpty(fileNameLocal)) { var arrDocument = fileNameLocal.Split(','); foreach (var item in arrDocument) { var arrDocumentChild = item.Split(':'); var folder = DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day + "\\"; var folderinsert = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; var urlFolder = ConfigData.DocumentFolder + folder; if (!Directory.Exists(urlFolder)) { Directory.CreateDirectory(urlFolder); } if (arrDocumentChild.Length > 1) { var fileLocal = arrDocumentChild[0].Split('.'); var fileName = FDIUtils.Slug(fileLocal[0]) + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + fileLocal[1]; var fileTemp = FDIUtils.Slug(fileLocal[0]) + "." + fileLocal[1]; System.IO.File.Copy(ConfigData.TempFolder + fileTemp, ConfigData.DocumentFolder + folder + fileName); var documentFile = new DocumentFile { Folder = folderinsert, FileUrl = fileName, DateCreated = DateTime.Now, FileSize = Convert.ToInt32(arrDocumentChild[1]), TypeFile = fileLocal[1], Status = true, }; var documentFilesDa = new DocumentFilesDA(); documentFile.Name = fileName; documentFilesDa.Add(documentFile); documentFilesDa.Save(); } } } }
public List <ProductAppIG4Item> GetProductForMap(string name, double minKm, double maxKm, int cateid, int minPrice, int maxPrice, double Latitude, double Longitude, int page, int pagesize, bool HasTransfer, int shopid) { if (!string.IsNullOrEmpty(name)) { name = String.Join(",", FDIUtils.Slug(FDIUtils.NewUnicodeToAscii(name)).Split('_').ToList()); } var query = FDIDB.ProductFull(name, maxKm, minKm, cateid, Latitude, Longitude, minPrice, maxPrice, page, pagesize, HasTransfer, shopid) .Select(l => new ProductAppIG4Item { ID = l.id ?? 0, Name = l.Name, PriceNew = l.PriceNew, UrlPicture = l.Folder + l.Url, kc = l.kc, IsPrestige = l.IsPrestige, IsPrestige1 = l.IsPrestige1, CateId = l.CateId, Km = l.km, Sort = l.sort }); return(query.ToList()); }
public ActionResult AnswerActions() { var msg = new JsonMessage(); var answer = new FAQ_Answer(); List <FAQ_Answer> ltsAnswerItems; StringBuilder stbMessage; switch (DoAction) { case ActionType.Add: UpdateModel(answer); answer.TitleAscii = FDIUtils.Slug(answer.Title); answer.DateCreated = DateTime.Now; _answerDa.Add(answer); _answerDa.Save(); msg = new JsonMessage { Erros = false, ID = answer.ID.ToString(), Message = string.Format("Đã thêm mới câu trả lời: <b>{0}</b>", Server.HtmlEncode(answer.Title)) }; break; case ActionType.Edit: answer = _answerDa.GetById(ArrId.FirstOrDefault()); UpdateModel(answer); answer.TitleAscii = FDIUtils.Slug(answer.Title); _answerDa.Save(); msg = new JsonMessage { Erros = false, ID = answer.ID.ToString(), Message = string.Format("Đã cập nhật câu trả lời: <b>{0}</b>", Server.HtmlEncode(answer.Title)) }; break; case ActionType.Delete: ltsAnswerItems = _answerDa.GetListByArrID(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsAnswerItems) { _answerDa.Delete(item); stbMessage.AppendFormat("Đã xóa câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } msg.ID = string.Join(",", ArrId); _answerDa.Save(); msg.Message = stbMessage.ToString(); break; case ActionType.Show: ltsAnswerItems = _answerDa.GetListByArrID(ArrId).Where(o => !o.IsShow).ToList(); //Chỉ lấy những đối tượng ko được hiển thị stbMessage = new StringBuilder(); foreach (var item in ltsAnswerItems) { item.IsShow = true; stbMessage.AppendFormat("Đã hiển thị câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } _answerDa.Save(); msg.ID = string.Join(",", ltsAnswerItems.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.Hide: ltsAnswerItems = _answerDa.GetListByArrID(ArrId).Where(o => o.IsShow).ToList(); //Chỉ lấy những đối tượng được hiển thị stbMessage = new StringBuilder(); foreach (var item in ltsAnswerItems) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn câu trả lời <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } _answerDa.Save(); msg.ID = string.Join(",", ltsAnswerItems.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; } if (string.IsNullOrEmpty(msg.Message)) { msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var question = new FAQ_Question(); List <FAQ_Question> ltsQuestionItems; StringBuilder stbMessage; if (Request["do"] != null && Request["do"] == "reply") { try { question = _questionDa.GetById(ArrId.FirstOrDefault()); var content = question.Content; UpdateModel(question); if (question.FAQ_Answer != null && question.FAQ_Answer.FirstOrDefault() != null) { var answer = question.FAQ_Answer.FirstOrDefault(); if (answer != null) { answer.Content = question.Content; question.Content = content; answer.DateCreated = DateTime.Now; answer.IsShow = true; } } else { var faqAnswer = new FAQ_Answer { Content = question.Content }; question.Content = content; faqAnswer.DateCreated = DateTime.Now; faqAnswer.IsShow = true; if (question.FAQ_Answer != null) { question.FAQ_Answer.Add(faqAnswer); } } _questionDa.Save(); msg = new JsonMessage { Erros = false, Message = "Đã trả lời câu hỏi" }; } catch (Exception) { } return(Json(msg, JsonRequestBehavior.AllowGet)); } switch (DoAction) { case ActionType.Add: UpdateModel(question); question.TitleAscii = FDIUtils.Slug(question.Title); question.DateCreated = DateTime.Now; question.LanguageId = Fdisystem.LanguageId; _questionDa.Add(question); _questionDa.Save(); msg = new JsonMessage { Erros = false, ID = question.ID.ToString(), Message = string.Format("Đã thêm mới câu hỏi: <b>{0}</b>", Server.HtmlEncode(question.Title)) }; break; case ActionType.Edit: question = _questionDa.GetById(ArrId.FirstOrDefault()); UpdateModel(question); _questionDa.Save(); msg = new JsonMessage { Erros = false, ID = question.ID.ToString(), Message = string.Format("Đã cập nhật câu hỏi: <b>{0}</b>", Server.HtmlEncode(question.Title)) }; break; case ActionType.Delete: ltsQuestionItems = _questionDa.GetListByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsQuestionItems) { _questionDa.Delete(item); stbMessage.AppendFormat("Đã xóa câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } msg.ID = string.Join(",", ArrId); _questionDa.Save(); msg.Message = stbMessage.ToString(); break; case ActionType.Show: ltsQuestionItems = _questionDa.GetListByArrId(ArrId).Where(o => o.IsShow == false).ToList(); stbMessage = new StringBuilder(); foreach (var item in ltsQuestionItems) { item.IsShow = true; stbMessage.AppendFormat("Đã hiển thị câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } _questionDa.Save(); msg.ID = string.Join(",", ltsQuestionItems.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.Hide: ltsQuestionItems = _questionDa.GetListByArrId(ArrId).Where(o => o.IsShow == true).ToList(); stbMessage = new StringBuilder(); foreach (var item in ltsQuestionItems) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn câu hỏi <b>{0}</b>.<br />", Server.HtmlEncode(item.Title)); } _questionDa.Save(); msg.ID = string.Join(",", ltsQuestionItems.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; } if (string.IsNullOrEmpty(msg.Message)) { msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Add() { var model = new ProductAppIG4Item(); UpdateModel(model); List <Gallery_Picture> images = new List <Gallery_Picture>(); for (int i = 0; i < Request.Files.Count; i++) { var img = await UploadImage(i); if (img.Code != 200) { return(Json(img)); } var picture = new Gallery_Picture { Type = !string.IsNullOrEmpty(Request["type"]) ? Convert.ToInt32(Request["type"]) : 0, CategoryID = model.CateId, Folder = img.Data.Folder, Name = img.Data.Name, DateCreated = DateTime.Now.TotalSeconds(), IsShow = true, Url = img.Data.Url, IsDeleted = false, }; images.Add(picture); _da.Add(picture); } if (images.Count == 0) { return(Json(new JsonMessage(1000, "Ảnh sản phẩn không được để trống."))); } await _da.SaveAsync(); //lay address var address = customerAddressDA.GetById(model.AddressId, CustomerId); if (address == null) { return(Json(new JsonMessage(1000, "Địa chỉ không tồn tại."))); } var product = new Shop_Product { Name = model.Name, NameAscii = FDIUtils.Slug(FDIUtils.NewUnicodeToAscii(model.Name)), Quantity = model.Quantity, Description = model.Description, PriceNew = model.PriceNew, PictureID = images[0].ID, CustomerID = CustomerId, freeShipFor = model.freeShipFor, HasTransfer = model.HasTransfer, Type = model.Type, IsShow = true, IsDelete = false, AddressId = address.ID, Latitude = address.Latitude.Value, CategoryId = model.CateId.Value, Longitude = address.Longitude.Value, DateCreated = DateTime.Now.TotalSeconds(), CustomerID1 = model.CustomerId1, //Gallery_Picture1 = _productDa.GetListPictureByArrId(images.Select(m => m.ID).ToList()), }; //product.Categories = _productDa.GetListCategoryByArrId(new List<int>() { model.CateId.Value }); _productDa.Add(product); await _productDa.SaveAsync(); return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var brand = new Shop_Brand(); List <int> idValues; List <string> idValuesTag; List <Shop_Brand> brandSelected; var pictureId = Request["Value_DefaultImages"]; switch (DoAction) { case ActionType.Add: try { UpdateModel(brand); if (!string.IsNullOrEmpty(pictureId)) { brand.PictureID = int.Parse(pictureId); } brand.IsDeleted = false; brand.ParentID = 1; brand.LanguageId = Fdisystem.LanguageId; brand.NameAscii = FDIUtils.Slug(brand.Name); _brandDa.Add(brand); _brandDa.Save(); msg = new JsonMessage { Erros = false, ID = brand.ID.ToString(), Message = string.Format("Đã thêm mới <b>{0}</b>", Server.HtmlEncode(brand.Name)) }; } catch (Exception ex) { LogHelper.Instance.LogError(GetType(), ex); } break; case ActionType.Edit: try { brand = _brandDa.GetById(ArrId.FirstOrDefault()); UpdateModel(brand); brand.NameAscii = FDIUtils.Slug(brand.Name); if (!string.IsNullOrEmpty(pictureId)) { brand.PictureID = int.Parse(pictureId); } else { brand.PictureID = null; } _brandDa.Save(); msg = new JsonMessage { Erros = false, ID = brand.ID.ToString(), Message = string.Format("Đã cập nhật <b>{0}</b>", Server.HtmlEncode(brand.Name)) }; } catch (Exception ex) { LogHelper.Instance.LogError(GetType(), ex); } break; case ActionType.Show: var ltsBrandItemsshow = _brandDa.GetListByArrId(ArrId); var stbMessageshow = new StringBuilder(); foreach (var item in ltsBrandItemsshow) { item.IsShow = true; stbMessageshow.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } msg.ID = string.Join(",", ArrId); _brandDa.Save(); msg.Message = stbMessageshow.ToString(); break; case ActionType.Hide: var ltsBrandItemshide = _brandDa.GetListByArrId(ArrId); var stbMessagehide = new StringBuilder(); foreach (var item in ltsBrandItemshide) { item.IsShow = false; stbMessagehide.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } msg.ID = string.Join(",", ArrId); _brandDa.Save(); msg.Message = stbMessagehide.ToString(); break; case ActionType.Delete: var ltsBrandItems = _brandDa.GetListByArrId(ArrId); var stbMessage = new StringBuilder(); foreach (var item in ltsBrandItems) { if (item.Shop_Product.Any()) { stbMessage.AppendFormat("<b>{0}</b> đang được sử dụng, không được phép xóa.<br />", Server.HtmlEncode(item.Name)); } else { _brandDa.Delete(item); stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } } msg.ID = string.Join(",", ArrId); _brandDa.Save(); msg.Message = stbMessage.ToString(); break; } if (string.IsNullOrEmpty(msg.Message)) { msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var partner = new Partner(); List <Partner> ltsPartner; StringBuilder stbMessage; List <int> idValues; var images = Request["Value_Images"]; var lstimages = Request["Value_ImagesProducts"]; switch (DoAction) { case ActionType.Add: try { UpdateModel(partner); partner.LanguageId = Fdisystem.LanguageId; partner.Slug = FDIUtils.Slug(partner.Name); partner.DateCreated = DateTime.Now; if (!string.IsNullOrEmpty(images)) { partner.PictureID = Convert.ToInt32(images); } if (!string.IsNullOrEmpty(lstimages)) { var lstInt = FDIUtils.StringToListInt(lstimages); partner.Gallery_Picture1 = _da.GetListPictureByArrId(lstInt); } partner.IsDeleted = false; _da.Add(partner); _da.Save(); msg = new JsonMessage { Erros = false, ID = partner.ID.ToString(), Message = string.Format("Đã thêm mới bài viết: <b>{0}</b>", Server.HtmlEncode(partner.Name)) }; } catch (Exception ex) { LogHelper.Instance.LogError(GetType(), ex); } break; case ActionType.Edit: try { partner = _da.GetById(ArrId.FirstOrDefault()); UpdateModel(partner); if (!string.IsNullOrEmpty(images)) { partner.PictureID = Convert.ToInt32(images); } partner.Gallery_Picture1.Clear(); if (!string.IsNullOrEmpty(lstimages)) { var lstInt = FDIUtils.StringToListInt(lstimages); partner.Gallery_Picture1 = _da.GetListPictureByArrId(lstInt); } _da.Save(); msg = new JsonMessage { Erros = false, ID = partner.ID.ToString(), Message = string.Format("Đã cập nhật bài viết: <b>{0}</b>", Server.HtmlEncode(partner.Name)) }; } catch (Exception ex) { LogHelper.Instance.LogError(GetType(), ex); } break; case ActionType.Delete: ltsPartner = _da.GetListByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsPartner) { try { item.IsDeleted = true; stbMessage.AppendFormat("Đã xóa bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); _da.Save(); } catch (Exception ex) { LogHelper.Instance.LogError(GetType(), ex); } } msg.ID = string.Join(",", ArrId); _da.Save(); msg.Message = stbMessage.ToString(); break; case ActionType.Show: ltsPartner = _da.GetListByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsPartner) { item.IsShow = true; stbMessage.AppendFormat("Đã hiển thị bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } _da.Save(); msg.ID = string.Join(",", ltsPartner.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.Hide: ltsPartner = _da.GetListByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsPartner) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn bài viết <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } _da.Save(); msg.ID = string.Join(",", ltsPartner.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; } if (string.IsNullOrEmpty(msg.Message)) { msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); switch (DoAction) { case ActionType.Add: msg = new JsonMessage(false, "Cập nhât dữ liệu thành công."); var lstFile = Request["lstFile"]; var lstP = JsonConvert.DeserializeObject <List <FileUploadItem> >(lstFile); try { if (lstP.Count > 0) { foreach (var item in lstP) { var folder = DateTime.Now.Year + "\\" + DateTime.Now.Month + "\\" + DateTime.Now.Day + "\\"; var folderinsert = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; var urlFolder = ConfigData.DocumentFolder + folder; if (!Directory.Exists(urlFolder)) { Directory.CreateDirectory(urlFolder); } if (item.Url.Length > 1) { var fileLocal = item.Url.Split('.'); var fileName = FDIUtils.Slug(fileLocal[0]) + "." + fileLocal[1]; System.IO.File.Copy(ConfigData.TempFolder + fileName, urlFolder + fileName); var fileItem = new DocumentFile { Folder = folderinsert, FileUrl = fileName, DateCreated = DateTime.Now, TypeFile = fileLocal[1], Status = true, IsDeleted = false, Name = item.Name }; _da.Add(fileItem); } } } _da.Save(); } catch (Exception ex) { msg.Erros = true; Log2File.LogExceptionToFile(ex); msg.Message = "Dữ liệu chưa được cập nhật."; } break; case ActionType.Edit: msg = new JsonMessage(false, "Cập nhât dữ liệu thành công."); try { var model = _da.GetById(ArrId.FirstOrDefault()); UpdateModel(model); _da.Save(); } catch (Exception ex) { msg.Erros = true; Log2File.LogExceptionToFile(ex); msg.Message = "Dữ liệu chưa được cập nhật."; } break; case ActionType.Delete: msg = new JsonMessage(false, "Xóa dữ liệu thành công."); try { var lst = _da.GetListByArrId(ArrId); foreach (var item in lst) { item.IsDeleted = true; } _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được xóa"; } break; default: msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; break; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(false, "Cập nhật dữ liệu thành công."); var document = new Document(); List <Document> ltsDocuments; StringBuilder stbMessage; List <int> idValues; List <int> lstFileOld; List <int> lstFileNews; var lstFiles = Request["getFiles"]; switch (DoAction) { case ActionType.Add: try { UpdateModel(document); document.Slug = FDIUtils.Slug(document.Name); document.LanguageId = Fdisystem.LanguageId; _da.Add(document); _da.Save(); if (!string.IsNullOrEmpty(Request["lstFile"])) { UploadDocument(Request["lstFile"], document.Id); } } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được cập nhật"; Log2File.LogExceptionToFile(ex); } break; case ActionType.Edit: try { document = _da.GetById(ArrId.FirstOrDefault()); UpdateModel(document); document.Slug = FDIUtils.Slug(document.Name); _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được cập nhật"; Log2File.LogExceptionToFile(ex); } break; case ActionType.Delete: ltsDocuments = _da.GetListByArrId(ArrId); foreach (var item in ltsDocuments) { item.IsDeleted = true; } _da.Save(); break; case ActionType.Show: ltsDocuments = _da.GetListByArrId(ArrId); foreach (var item in ltsDocuments) { item.IsShow = true; } _da.Save(); break; case ActionType.Hide: ltsDocuments = _da.GetListByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in ltsDocuments) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn tài liệu <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } _da.Save(); break; default: msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; break; } return(Json(msg, JsonRequestBehavior.AllowGet)); }