public void SaveTourist(NewTouristModel newTourist) { using (var db = new SitesEntities()) { var searchedTourist = (from t in db.Tourists where t.AndroidID.Equals(newTourist.AndroidID) == true select t).FirstOrDefault(); if (searchedTourist == null) { Tourist addTourist = new Tourist(); addTourist.AndroidID = newTourist.AndroidID; addTourist.Username = newTourist.Username; addTourist.VisitedSites = 0; db.Tourists.Add(addTourist); db.SaveChanges(); } if (searchedTourist != null) { var updateTourist = db.Tourists.Find(searchedTourist.ID); updateTourist.VisitedSites = newTourist.VisitedSites; updateTourist.Username = newTourist.Username; db.SaveChanges(); } } }
public void SaveComment(PostCommentModel postedComment) { using (var db = new SitesEntities()) { SiteComment newComment = new SiteComment(); newComment.UserName = postedComment.UserName; newComment.Comment = postedComment.Comment; newComment.SiteID = postedComment.SiteID; db.SiteComments.Add(newComment); db.SaveChanges(); } }
public void SaveEvent(PostedEventModel postedEvent) { using (var db = new SitesEntities()) { SiteEvent newEvent = new SiteEvent(); newEvent.DateOfEvent = postedEvent.DateOfEvent; newEvent.EventDescription = postedEvent.EventDescription; newEvent.SiteID = postedEvent.SiteID; db.SiteEvents.Add(newEvent); db.SaveChanges(); } }