public User CreateSovaUser(User user, string password) { using (var db = new SovaContext()) { // validation if (string.IsNullOrWhiteSpace(password)) { throw new AppException("Password is required"); } if (db.Users.Any(x => x.Username == user.Username)) { throw new AppException("Username " + user.Username + " is already taken"); } byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; db.Users.Add(user); db.SaveChanges(); return(user); } }
public void UpdateMarking(Marking marking) { SovaContext db = new SovaContext(); db.Update(marking); db.SaveChanges(); }
//public List<Notes> ReadAll(int userid, PagingAttributes pagingAttributes) //{ // SovaContext db = new SovaContext(); // return db.Notes // .Where(x => x.Userid == userid) // .Skip(pagingAttributes.Page * pagingAttributes.PageSize) // .Take(pagingAttributes.PageSize).ToList(); //} public void Update(Notes updateNote) { SovaContext db = new SovaContext(); db.Update(updateNote); db.SaveChanges(); }
public void Delete(int id) { using (var db = new SovaContext()) { var user = db.Users.Find(id); if (user != null) { db.Users.Remove(user); db.SaveChanges(); } } }
public bool DeleteMarking(int markingId) { SovaContext db = new SovaContext(); var marking = db.Markings.Find(markingId); if (marking == null) { return(false); } db.Remove(marking); db.SaveChanges(); return(true); }
public bool Delete(int noteId) { SovaContext db = new SovaContext(); var note = db.Notes.Find(noteId); if (note == null) { return(false); } db.Remove(note); db.SaveChanges(); return(true); }
public bool DeleteAnnotationsByMarkingId(int id) { using (var db = new SovaContext()) { var annotation = db.Annotations.Where(x => x.MarkedPostId == id); foreach (var item in annotation) { db.Annotations.Remove(item); } db.SaveChanges(); return(true); } }
public bool DeleteAnnotation(int id) { using (var db = new SovaContext()) { var annotation = db.Annotations.FirstOrDefault(x => x.AnnotationId == id); if (annotation != null) { db.Annotations.Remove(annotation); db.SaveChanges(); return(true); } return(false); } }
////////////////Annotations public AnnotationsDTO AddAnnotation(int primaryKey, string text, int from, int to) { using (var db = new SovaContext()) { Annotations a = new Annotations(); a.MarkedPostId = primaryKey; a.Annotation = text; a.From = from; a.To = to; db.Add(a); db.SaveChanges(); return(new AnnotationsDTO(a.AnnotationId, a.MarkedPostId, a.Annotation, null, a.From, a.To)); } }
public AnnotationsDTO EditAnnotation(int id, string EditedText) { using (var db = new SovaContext()) { var annotation = db.Annotations.FirstOrDefault(x => x.AnnotationId == id); if (annotation != null) { annotation.Annotation = EditedText; db.SaveChanges(); return(new AnnotationsDTO(annotation.AnnotationId, annotation.MarkedPostId, annotation.Annotation, null, annotation.From, annotation.To)); } return(null); } }
public bool RemoveSearchHistory(int id) { using (var db = new SovaContext()) { var searchedItem = db.SearchHistory.Where(i => i.Id == id).FirstOrDefault(); if (searchedItem != null) { db.SearchHistory.Remove(searchedItem); db.SaveChanges(); return(true); } return(false); } }
public bool RemoveMarking(int id) { using (var db = new SovaContext()) { var marking = db.Markings.FirstOrDefault(m => m.MarkedPostId == id); if (marking != null) { DeleteAnnotationsByMarkingId(id); db.Markings.Remove(marking); db.SaveChanges(); return(true); } return(false); } }
public void Create(Notes note) { SovaContext db = new SovaContext(); var tmp = db.Notes.ToList(); if (tmp.Count == 0) { note.Id = 1; } else { note.Id = db.Notes.Max(x => x.Id) + 1; } db.Add(note); db.SaveChanges(); }
public bool RemoveMarking(int uid, int id) { using (var db = new SovaContext()) { var marking = db.Markings.Where(u => u.UserId == uid).Where(p => p.PostId == id).FirstOrDefault(); if (marking != null) { DeleteAnnotationsByMarkingId(marking.MarkedPostId); db.Markings.Remove(marking); db.SaveChanges(); return(true); } return(false); } }
public bool Delete(int userId, DateTime timestamp) { SovaContext db = new SovaContext(); try { db.Histories.Remove(Read(userId, timestamp)[0]); db.SaveChanges(); return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } }
public void CreateMarking(Marking marking) { SovaContext db = new SovaContext(); var tmpList = db.Markings.ToList(); if (tmpList.Count == 0) { marking.Id = 1; } else { marking.Id = db.Markings.Max(x => x.Id) + 1; } db.Add(marking); db.SaveChanges(); }
public bool DeleteUserCustomeField(int id) { using (var db = new SovaContext()) { var customeField = db.UserCustomeField.Where(i => i.Id == id).FirstOrDefault(); if (customeField != null) { var favoriteTagsOfC = db.FavoriteTags.Where(i => i.UserCustomeFieldId == id); foreach (var item in favoriteTagsOfC) { db.FavoriteTags.Remove(item); } db.UserCustomeField.Remove(customeField); db.SaveChanges(); return(true); } return(false); } }
public void UpdateSovaUser(User userParam, string password = null) { using (var db = new SovaContext()) { var user = db.Users.Find(userParam.Id); if (user == null) { throw new AppException("User not found"); } if (userParam.Username != user.Username) { // username has changed so check if the new username is already taken if (db.Users.Any(x => x.Username == userParam.Username)) { throw new AppException("Username " + userParam.Username + " is already taken"); } } // update user properties user.FirstName = userParam.FirstName; user.LastName = userParam.LastName; user.Username = userParam.Username; // update password if it was entered if (!string.IsNullOrWhiteSpace(password)) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } db.Users.Update(user); db.SaveChanges(); } }