public void Add(PersonSubject entity) { if (!_dbContext.PersonSubjects.ToList().Exists(x => x.PersonID == entity.PersonID && x.Name == entity.Name)) { _dbContext.PersonSubjects.Add(entity); _dbContext.SaveChanges(); } }
public void RemoveMatch(Guid id2) { using (var context = new UniBinderEF()) { var match = context.MatchedPeoples.Where(x => x.SecondPersonID == id2).FirstOrDefault(); context.Entry(match).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public void AddNewMatch(Guid victimID, string checkID) { using (var context = new UniBinderEF()) { context.MatchedPeoples.Add(new MatchedPeople { FirstPersonID = new Guid(checkID), SecondPersonID = victimID, Id = Guid.NewGuid() }); context.SaveChanges(); } }
private void AddSubjects(PersonSubject personSubject) { using (var context = new UniBinderEF()) { if (!context.PersonSubjects.ToList().Exists(x => x.PersonID == personSubject.PersonID && x.Name == personSubject.Name)) { context.PersonSubjects.Add(personSubject); context.SaveChanges(); } } }
public IHttpActionResult UpdateUser([FromBody] Person updatedUser) { if (updatedUser == null) { return(BadRequest()); } var currentUser = GetCurrentUser(updatedUser); if (currentUser == null) { return(NotFound()); } Person user = new Person() { Name = updatedUser.Name, Password = updatedUser.Password, Surname = updatedUser.Surname, Email = updatedUser.Email, ID = updatedUser.ID, SubjectList = updatedUser.SubjectList }; if (user.SubjectList == null) { using (var db = new UniBinderEF()) { db.People.Attach(user); if (user.Password != null) { db.Entry(user).Property(x => x.Password).IsModified = true; } db.Entry(user).Property(x => x.Name).IsModified = true; db.Entry(user).Property(x => x.Surname).IsModified = true; db.Entry(user).Property(x => x.Email).IsModified = true; try { db.SaveChanges(); } catch (Exception) { return(BadRequest()); } } return(Ok()); } else { userDataInserter.LinkSubjectsToPersonDataTable(user); //userDataInserter.LinkSubjectsToPersonWithDel(user); //slower by 1.5 sec return(Ok()); } }
public bool UpdatePersonInfo(Person p) { using (var context = new UniBinderEF()) { var person = context.People.SingleOrDefault(x => x.ID == p.ID); if (person != null) { person.ImageLink = p.ImageLink; person.Name = p.Name; person.Surname = p.Surname; person.Username = p.Username; person.Age = p.Age; person.SubjectList = p.SubjectList; LinkSubjectsToPersonWithDel(person); context.SaveChanges(); return(true); } return(false); } }
public void Add(Person entity) { _dbContext.People.Add(entity); _dbContext.SaveChanges(); }