public ActionResult Add(Clothes model, int clothesTypeId) { lock (_lockObj) { if (!ValidClothesSize(model.ClothesSize)) return new JsonResult() { Data = false }; if (!ValidateClothes(model)) return new JsonResult() { Data = "大货编号或样板编号已存在" }; var pinglei = DbContext.ClothesParts.FirstOrDefault(t => t.Name == "品类" && t.ClothType.Id == clothesTypeId); Clothes c = new Clothes() { Comment = model.Comment, ProductedCount = model.ProductedCount, SaledCount = model.SaledCount, SampleNO = model.SampleNO ?? string.Empty, ProductNO = model.ProductNO ?? string.Empty, AssessoriesFile = model.AssessoriesFile ?? string.Empty, ClothesPics = model.ClothesPics ?? string.Empty, ClothesSize = model.ClothesSize ?? string.Empty, ModelVersionPics = model.ModelVersionPics ?? string.Empty, SampleFile = model.SampleFile ?? string.Empty, StylePics = model.StylePics ?? string.Empty, TechnologyFile = model.TechnologyFile ?? string.Empty, Tags = model.Tags ?? string.Empty, ClothesType = DbContext.ClothesTypes.SingleOrDefault(t => t.Id == clothesTypeId), Owner = CurrentUser }; string tmp = string.Empty; if (pinglei != null) { var tags = model.Tags.Split(new char[] { ',' }).ToList(); foreach (var t in tags) { foreach (var pt in pinglei.PartTypes) { if (t.Contains(pt.Name)) { tmp = pt.Name; } } } if (string.Empty != tmp) c.PingLei = tmp; } DbContext.Clothes.Add(c); DbContext.OperationLogs.Add(new OperationLog() { User = CurrentUser, Clothes = c, OperationType = OperationType.AddClothes.ToString() }); DbContext.SaveChanges(); SaveClothesHelper.Save(c); return new JsonResult() { Data = true }; } }
public static void Save(Clothes clothes) { using (IndexWriter writer = new IndexWriter(directory, analyzer, !directory.FileExists("segments.gen"), new IndexWriter.MaxFieldLength(1000))) { Document document = new Document(); document.Add(new Field(Fields.Id.ToString(), clothes.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.SampleNoIndex.ToString(), PREFIX + (clothes.SampleNO ?? "").ToLower() + SUBFIX, Field.Store.NO, Field.Index.ANALYZED)); document.Add(new Field(Fields.SampleNO.ToString(), clothes.SampleNO, Field.Store.YES, Field.Index.NO)); document.Add(new Field(Fields.Tags.ToString(), clothes.Tags.Replace(',', ' '), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.ProductNO.ToString(), clothes.ProductNO, Field.Store.YES, Field.Index.NO)); document.Add(new Field(Fields.ProductNOIndex.ToString(), PREFIX + (clothes.ProductNO ?? "").ToLower() + SUBFIX, Field.Store.NO, Field.Index.ANALYZED)); document.Add(new Field(Fields.Year.ToString(), ExtractYearFromTags(clothes), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.ClothesTypeId.ToString(), clothes.ClothesType.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.SaledCount.ToString(), clothes.SaledCount.ToString(), Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.ClothesPics.ToString(), clothes.ClothesPics ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.ModelVersionPics.ToString(), clothes.ModelVersionPics ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.StylePics.ToString(), clothes.StylePics ?? string.Empty, Field.Store.YES, Field.Index.ANALYZED)); document.Add(new Field(Fields.UsedCount.ToString(), clothes.ViewCount.ToString(), Field.Store.YES, Field.Index.ANALYZED)); //store Tags var tags = clothes.Tags.Split(new char[] { ',' }); Dictionary<string, string> dics = new Dictionary<string, string>(); Array.ForEach(tags, t => { if (t.IndexOf('-') > -1) { var key = t.Substring(0, t.IndexOf('-')); var value = t.Substring(t.IndexOf('-') + 1); if (dics.ContainsKey(key)) { dics[key] = dics[key] + "," + PREFIX + value.ToLower() + SUBFIX; } else { dics.Add(key, PREFIX + value.ToLower() + SUBFIX); } } }); dics.Keys.ToList().ForEach(k => { document.Add(new Field(k, dics[k], Field.Store.YES, Field.Index.ANALYZED)); }); writer.AddDocument(document); writer.Optimize(); } }
private static string ExtractYearFromTags(Clothes clothes) { if (!String.IsNullOrEmpty(clothes.Tags)) { return System.Text.RegularExpressions.Regex.Match(clothes.Tags, @"\d{4}").Value; } return string.Empty; }
private bool ValidateClothes(Clothes clothes) { return DbContext.Clothes.FirstOrDefault(t => (t.ProductNO == clothes.ProductNO || t.SampleNO == clothes.SampleNO) && t.IsDeleted == false) == null; }
public ActionResult Edit(Clothes model) { Clothes c = DbContext.Clothes.SingleOrDefault(t => t.Id == model.Id); if (c != null) { c.Comment = model.Comment; c.ProductedCount = model.ProductedCount; c.SaledCount = model.SaledCount; c.SampleNO = c.SampleNO; c.ProductNO = c.ProductNO; c.AssessoriesFile = model.AssessoriesFile ?? string.Empty; c.ClothesPics = model.ClothesPics ?? string.Empty; c.ClothesSize = model.ClothesSize ?? string.Empty; c.ModelVersionPics = model.ModelVersionPics ?? string.Empty; c.SampleFile = model.SampleFile ?? string.Empty; c.StylePics = model.StylePics ?? string.Empty; c.TechnologyFile = model.TechnologyFile ?? string.Empty; DbContext.OperationLogs.Add(new OperationLog() { User = CurrentUser, Clothes = c, OperationType = OperationType.EditClothes.ToString() }); DbContext.SaveChanges(); SaveClothesHelper.RemoveDocument(c.Id); SaveClothesHelper.Save(c); return new ContentResult() { Content = "true" }; } return new ContentResult() { Content = "false" }; }
private string GetPathFile(Clothes clothes, string type) { switch (type) { case "SampleFile": return clothes.SampleFile; case "TechnologyFile": return clothes.TechnologyFile; case "AssessoriesFile": return clothes.AssessoriesFile; default: return "NOTFOUND"; } }