public async Task <User> CreateUser(string email, string password, string name = "")
        {
            User user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Email == email);

            if (user is null)
            {
                string guid     = Guid.NewGuid().ToString().Replace("-", "_");
                string userName = string.IsNullOrEmpty(name) ? email : name;
                user = new User
                {
                    Email        = email,
                    Password     = password,
                    Id           = "user_" + guid,
                    Name         = userName,
                    RegisterDate = DateTime.Now
                };
                _dbContext.Add(user);
                await _dbContext.SaveChangesAsync();

                return(user);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Todo> > Put([FromBody] Models.Todo todo)
        {
            var newTodo = await _dataManager.Todos.GetTodoById(todo.Id);

            if (newTodo is null)
            {
                return(BadRequest("todo is null"));
            }
            newTodo.Text        = todo.Text;
            newTodo.IsComplited = todo.IsComplited;
            _context.Todos.Update(newTodo);
            await _context.SaveChangesAsync();

            return(Ok(newTodo));
        }
Ejemplo n.º 3
0
        public async Task <Slovechko> CreateSlovo(string content, string autor)
        {
            var guid  = Guid.NewGuid().ToString().Replace("-", "_");
            var slovo = new Slovechko()
            {
                Id = $"slovechko_{guid}"
            };

            slovo.Author  = autor;
            slovo.Content = content;
            await _contex.Slovechkos.AddAsync(slovo);

            await _contex.SaveChangesAsync();

            return(slovo);
        }
Ejemplo n.º 4
0
 public void Change(Todo todo)
 {
     _dbContext.Todos.Update(todo);
     _dbContext.SaveChangesAsync();
 }