public void AddOffer(Offer offer, String name, string tg) { offer.DateAdded = DateTime.Now; offer.Tags = new List<Tag>(); var separators = new char[] {' '}; var tags = tg.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string t in tags) { var tag = FindTagByValue(t); if (tag == null) { tag = new Tag(); tag.Value = t; } offer.Tags.Add(tag); } var user = FindUserByName(name); if (user != null) { offer.User = user; _db.Offers.Add(offer); user.Offers.Add(offer); _db.SaveChanges(); } }
public ActionResult Index(Offer offer, UploadPhotoModel photo, string tg, int? updOfferId) { if (photo.FirstPostedFile != null) { string pic = (new Random()).Next(2, 2000000000).ToString() + System.IO.Path.GetExtension(photo.FirstPostedFile.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Images"), pic); // file is uploaded photo.FirstPostedFile.SaveAs(path); offer.FirstPhotoPath = "/Images/" + pic; } if (photo.SecondPostedFile != null) { string pic = (new Random()).Next(2, 2000000000).ToString() + System.IO.Path.GetExtension(photo.SecondPostedFile.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Images"), pic); // file is uploaded photo.SecondPostedFile.SaveAs(path); offer.SecondPhotoPath = "/Images/" + pic; } if (photo.ThirdPostedFile != null) { string pic = (new Random()).Next(2, 2000000000).ToString() + System.IO.Path.GetExtension(photo.ThirdPostedFile.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Images"), pic); // file is uploaded photo.ThirdPostedFile.SaveAs(path); offer.ThirdPhotoPath = "/Images/" + pic; } if (updOfferId != null) { _repo.UpdateOffer((int)updOfferId, offer, User.Identity.Name, tg); } else { _repo.AddOffer(offer, User.Identity.Name, tg); } return RedirectToAction("Index", "Home"); }
public static void AddUpdateLuceneIndex(Offer sampleData) { AddUpdateLuceneIndex(new List<Offer> { sampleData }); }
private static void _addToLuceneIndex(Offer sampleData, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString())); writer.DeleteDocuments(searchQuery); // add new index entry var doc = new Document(); // add lucene fields mapped to db fields doc.Add(new Field("Id", sampleData.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Name", sampleData.Title, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Description", sampleData.Description, Field.Store.YES, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(doc); }
public void UpdateOffer(int updOfferId, Offer offer, String name, string tg) { offer.Tags = new List<Tag>(); var separators = new char[] { ' ' }; var tags = tg.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string t in tags) { var tag = FindTagByValue(t); if (tag == null) { tag = new Tag(); tag.Value = t; } offer.Tags.Add(tag); } var updOffer = FindOfferById(updOfferId); updOffer.Title = offer.Title; updOffer.Tags.Clear(); foreach (Tag newTag in offer.Tags) { updOffer.Tags.Add(newTag); } updOffer.Description = offer.Description; updOffer.Price = offer.Price; if (offer.FirstPhotoPath != null) { updOffer.FirstPhotoPath = offer.FirstPhotoPath; } if (offer.SecondPhotoPath != null) { updOffer.SecondPhotoPath = offer.SecondPhotoPath; } if (offer.ThirdPhotoPath != null) { updOffer.ThirdPhotoPath = offer.ThirdPhotoPath; } _db.SaveChanges(); }