public Models.Challenge Save(Models.Challenge challenge) { if (challenge.Id == 0) { _context.Challenges.Add(challenge); _context.SaveChanges(); return(_context.Challenges.Last()); } else { var update = _context.Challenges.Where(x => x.Id == challenge.Id).SingleOrDefault(); update = challenge; _context.SaveChanges(); return(update); } }
public User Save(User user) { User Result; if (user.Id == 0) { db.Users.Add(user); Result = user; } else { Result = FindById(user.Id); Result.FullName = user.FullName; Result.Email = user.Email; Result.Nickname = user.Nickname; Result.Password = user.Password; Result.CreateAt = user.CreateAt; } db.SaveChanges(); return(Result); }
public User Save(User user) { if (user.Id == 0) { _context.Users.Add(user); _context.SaveChanges(); return(_context.Users.Last()); } else { var update = _context.Users.Where(x => x.Id == user.Id).First(); update = user; _context.SaveChanges(); return(update); } }
public Acceleration Save(Acceleration acceleration) { var accelerationInDatabase = _context.Accelerations .FirstOrDefault(a => a.Id == acceleration.Id); bool forCreate = accelerationInDatabase == null; Acceleration savedAcceleration; if (forCreate) { savedAcceleration = (_context.Accelerations.Add(acceleration)).Entity; } else { accelerationInDatabase.Name = acceleration.Name ?? acceleration.Name; accelerationInDatabase.Slug = acceleration.Slug ?? acceleration.Slug; accelerationInDatabase.ChallengeId = acceleration.ChallengeId == 0? accelerationInDatabase.ChallengeId : acceleration.ChallengeId; savedAcceleration = (_context.Accelerations.Update(accelerationInDatabase)).Entity; } _context.SaveChanges(); return(savedAcceleration); }
public Submission Save(Submission submission) { if (submission.ChallengeId == 0 || submission.UserId == 0) { return(null); } var submissionInDatabase = _context.Submissions .FirstOrDefault(s => s.UserId == submission.UserId && s.ChallengeId == submission.ChallengeId); bool forCreate = submissionInDatabase == null; Submission savedSubmission; if (forCreate) { savedSubmission = (_context.Submissions.Add(submission)).Entity; } else { submissionInDatabase.Score = submission.Score; savedSubmission = (_context.Submissions.Update(submissionInDatabase)).Entity; } _context.SaveChanges(); return(savedSubmission); }
public User Save(User user) { var userInDatabase = _context.Users .FirstOrDefault(u => u.Id == user.Id); bool forCreate = userInDatabase == null; User savedUser; if (forCreate) { savedUser = (_context.Users.Add(user)).Entity; } else { userInDatabase.FullName = user.FullName ?? userInDatabase.FullName; userInDatabase.Email = user.Email ?? userInDatabase.Email; userInDatabase.Nickname = user.Nickname ?? userInDatabase.Nickname; userInDatabase.Password = user.Password ?? userInDatabase.Password; savedUser = (_context.Users.Update(userInDatabase)).Entity; } _context.SaveChanges(); return(savedUser); }
public User Save(User user) { codenationContext.Users.Add(user); codenationContext.SaveChanges(); return(user); }
public Candidate Save(Candidate candidate) { if (candidate.AccelerationId == 0 || candidate.CompanyId == 0 || candidate.UserId == 0) { return(null); } var candidateInDatabase = _context.Candidates .FirstOrDefault(c => c.UserId == candidate.UserId && c.AccelerationId == candidate.AccelerationId && c.CompanyId == candidate.CompanyId); bool forCreate = candidateInDatabase == null; Candidate savedCandidate; if (forCreate) { savedCandidate = (_context.Candidates.Add(candidate)).Entity; } else { candidateInDatabase.Status = candidate.Status; savedCandidate = (_context.Candidates.Update(candidateInDatabase)).Entity; } _context.SaveChanges(); return(savedCandidate); }
public User Save(User user) { var state = user.Id == 0 ? EntityState.Added : EntityState.Modified; context.Entry(user).State = state; context.SaveChanges(); return(user); }
public Company Save(Company company) { var state = company.Id == 0 ? EntityState.Added : EntityState.Modified; context.Entry(company).State = state; context.SaveChanges(); return(company); }
public Models.Challenge Save(Models.Challenge challenge) { var status = challenge.Id == 0 ? EntityState.Added : EntityState.Modified; context.Entry(challenge).State = status; context.SaveChanges(); return(challenge); }
public Acceleration Save(Acceleration acceleration) { var state = acceleration.Id == 0 ? EntityState.Added : EntityState.Modified; context.Entry(acceleration).State = state; context.SaveChanges(); return(acceleration); }
public Acceleration Save(Acceleration acceleration) {//deve retornar uma aceleração depois de salvar os dados. //Caso o Id seja zero, fará a inserção da aceleração, //caso contrário fará a atualização dos dados da aceleração com o Id informado if (acceleration.Id == 0) { _context.Accelerations.Add(acceleration); _context.SaveChanges(); return(_context.Accelerations.Last()); } else { var update = _context.Accelerations.Where(x => x.Id == acceleration.Id).SingleOrDefault(); update = acceleration; _context.SaveChanges(); return(update); } }
public Submission Save(Submission submission) { var existe = _context.Submissions.Find(submission.UserId, submission.ChallengeId) == null ? _context.Add(submission) : _context.Update(submission.Score); _context.SaveChanges(); return(submission); }
public Models.Challenge Save(Models.Challenge challenge) {//deve retornar um desafio após salvar os dados. //Caso o Id seja zero, fará a inserção da aceleração, //caso contrário fará a atualização dos dados da aceleração com o Id fornecido. if (challenge.Id == 0) { _context.Challenges.Add(challenge); _context.SaveChanges(); return(_context.Challenges.Last()); } else { var update = _context.Challenges.Where(x => x.Id == challenge.Id).SingleOrDefault(); update = challenge; _context.SaveChanges(); return(update); } }
public Submission Save(Submission submission) { if (!(_context.Submissions.Any(x => x.UserId == submission.UserId && x.ChallengeId == submission.ChallengeId))) //not exist { _context.Submissions.Add(submission); _context.SaveChanges(); return(_context.Submissions.Last()); } else { var update = _context.Submissions .Where(x => x.UserId == submission.UserId && x.ChallengeId == submission.ChallengeId) .SingleOrDefault(); update = submission; _context.SaveChanges(); return(update); } }
public Acceleration Save(Acceleration acceleration) { if (acceleration.Id == 0) { _context.Add(acceleration); _context.SaveChanges(); } return(acceleration); }
public Acceleration Save(Acceleration acceleration) { var estado = acceleration.Id == 0 ? EntityState.Added : EntityState.Modified; _contexto.Entry(acceleration).State = estado; _contexto.SaveChanges(); return(acceleration); }
public User Save(User user) { //deve retornar um usuário após salvar os dados. //Caso o Id seja zero, fará a inserção do usuário, //caso contrário fará a atualização dos dados do usuário com o Id informado if (user.Id == 0) { _context.Users.Add(user); _context.SaveChanges(); return(_context.Users.Last()); } else { var update = _context.Users.Where(x => x.Id == user.Id).SingleOrDefault(); update = user; _context.SaveChanges(); return(update); } }
public User Save(User user) { var estado = user.Id == 0 ? EntityState.Added : EntityState.Modified; _contexto.Entry(user).State = estado; _contexto.SaveChanges(); return(user); }
public Submission Save(Submission submission) { //deve retornar uma submissão após salvar os dados. Caso a tupla UserId e ChallengeId não exista, //fará a inserção da submissão, caso contrário fará a atualização dos dados da submissão if (!(_context.Submissions.Any(x => x.UserId == submission.UserId && x.ChallengeId == submission.ChallengeId))) //not exist { _context.Submissions.Add(submission); _context.SaveChanges(); return(_context.Submissions.Last()); } else //exist { var update = _context.Submissions .Where(x => x.UserId == submission.UserId && x.ChallengeId == submission.ChallengeId) .SingleOrDefault(); update = submission; _context.SaveChanges(); return(update); } }
public Models.Challenge Save(Models.Challenge challenge) { var estado = challenge.Id == 0 ? EntityState.Added : EntityState.Modified; _contexto.Entry(challenge).State = estado; _contexto.SaveChanges(); return(challenge); }
public Company Save(Company company) {//deve retorna uma empresa após salvar os dados. //Caso o Id da instância não seja fornecido, // fará a inserção da empresa, caso contrário fará a atualização dos dados da empresa com o Id informado //deve retornar um usuário após salvar os dados. Caso o Id seja zero, fará a inserção do usuário, //caso contrário fará a atualização dos dados do usuário com o Id informado if (FindById(company.Id) == null) { _context.Companies.Add(company); _context.SaveChanges(); return(_context.Companies.Last()); } else { var update = _context.Companies.Where(x => x.Id == company.Id).SingleOrDefault(); update = company; _context.SaveChanges(); return(update); } }
public Models.Challenge Save(Models.Challenge challenge) { if (challenge.Id.Equals(0)) { _context .Challenges .Add(challenge); _context .SaveChanges(); return(challenge); } else { _context .Entry(challenge) .State = EntityState.Modified; _context.SaveChanges(); return(challenge); } }
public Acceleration Save(Acceleration acceleration) { if (acceleration.Id.Equals(0)) { _context .Accelerations .Add(acceleration); _context .SaveChanges(); return(acceleration); } else { _context .Entry(acceleration) .State = EntityState.Modified; _context.SaveChanges(); return(acceleration); } }
public Company Save(Company company) { if (company.Id.Equals(0)) { _context .Companies .Add(company); _context .SaveChanges(); return(company); } else { _context .Entry(company) .State = EntityState.Modified; _context.SaveChanges(); return(company); } }
public Candidate Save(Candidate candidate) { var existsCandidate = _context .Candidates .Any(x => x.UserId.Equals(candidate.UserId) && x.AccelerationId.Equals(candidate.AccelerationId) && x.CompanyId.Equals(candidate.CompanyId)); if (!existsCandidate) { _context .Candidates .Add(candidate); _context .SaveChanges(); return(candidate); } else { _context.SaveChanges(); return(candidate); } }
public Submission Save(Submission submission) { var existsSubmission = _context .Submissions .Any(x => x.Equals(submission)); if (!existsSubmission) { _context .Submissions .Add(submission); _context .SaveChanges(); return(submission); } else { _context.SaveChanges(); return(submission); } }
public Candidate Save(Candidate candidate) {//deve retornar um candidato após salvar os dados. //Caso a tupla UserId, AccelartionId e CompanyId não exista, fará a inserção do candidato, //caso contrário fará a atualização dos dados do candidato if (!(_context.Candidates.Any(x => x.UserId == candidate.UserId && x.AccelerationId == candidate.AccelerationId && x.CompanyId == candidate.CompanyId))) //not exist { _context.Candidates.Add(candidate); _context.SaveChanges(); return(_context.Candidates.Last()); } else //exist { var update = _context.Candidates.Where(x => x.UserId == candidate.UserId && x.AccelerationId == candidate.AccelerationId && x.CompanyId == candidate.CompanyId).SingleOrDefault(); update = candidate; _context.SaveChanges(); return(update); } }
public Acceleration Save(Acceleration acceleration) { if (acceleration.Id <= 0) { Context.Accelerations.Add(acceleration); } else { Context.Accelerations.Update(acceleration); } Context.SaveChanges(); return(acceleration); }