Esempio n. 1
0
 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();
     }
 }
Esempio n. 2
0
 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();
 }