public General.ResponseResult CreateUser(SignUp model) { var user = _wordMeisterDbContext.Users.Where(w => w.Email == model.Email).FirstOrDefault(); if (user != null) { return(new General.ResponseResult() { Error = true, ErrorMessage = "There is a user that have same email" }); } _wordMeisterDbContext.Users.Add(new User { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Password = model.Password, CreatedDate = DateTime.Now, Guid = Guid.NewGuid(), Status = true, }); _wordMeisterDbContext.SaveChanges(); //TODO Send Email return(new General.ResponseResult()); }
public ResponseResult AddWord(WordRequest.Add model, int userId) { var existWord = _dbContext.Words.FirstOrDefault(x => x.Text == model.Text); var userWord = new UserWord(); if (existWord.IsNullOrDefault()) { var newWord = _dbContext.Words.Add(new Word { Text = model.Text, Sentences = null, CreatedDate = DateTime.Now, }); _dbContext.SaveChanges(); userWord = new UserWord { UserId = userId, WordId = newWord.Entity.Id, Description = model.Description, CreatedDate = DateTime.Now }; _dbContext.UserWords.Add(userWord); _dbContext.SaveChanges(); Task.Run(() => { AddWordModel(newWord.Entity); }); } else { var exist = _dbContext.UserWords.FirstOrDefault(x => x.UserId == userId && x.WordId == existWord.Id); if (!exist.IsNullOrDefault()) { return new ResponseResult() { Error = true, ErrorMessage = "Such a word has been added before." } } ; userWord = new UserWord { UserId = userId, WordId = existWord.Id, Description = model.Description, CreatedDate = DateTime.Now }; _dbContext.UserWords.Add(userWord); _dbContext.SaveChanges(); } return(new ResponseResult()); }