Exemplo n.º 1
0
        public virtual async Task <T> AddAsync(T entity)
        {
            _dbContext.Set <T>().Add(entity);
            await _dbContext.SaveChangesAsync();

            return(entity);
        }
Exemplo n.º 2
0
        public async Task EnsureSeedData()
        {
            _context.Database.EnsureCreated();

            _context.Tasks.RemoveRange(_context.Tasks);
            _context.SaveChanges();

            var task = new TaskEntity
            {
                Title       = "Read a book",
                TaskDetails = "Read Sadguru books"
            };

            _context.Add(task);

            var task2 = new TaskEntity
            {
                Title       = "Go to temple",
                TaskDetails = "Go to temple"
            };

            _context.Add(task2);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async System.Threading.Tasks.Task DeleteUser(int id)
        {
            using (var taskManagerDbContext = new TaskManagerDbContext())
            {
                var deletedUser = await GetUserById(id);

                taskManagerDbContext.Users.Remove(deletedUser);
                await taskManagerDbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 4
0
        public async Task <User> UpdateUser(User user)
        {
            using (var taskManagerDbContext = new TaskManagerDbContext())
            {
                taskManagerDbContext.Users.Update(user);
                await taskManagerDbContext.SaveChangesAsync();

                return(user);
            }
        }
Exemplo n.º 5
0
        public async System.Threading.Tasks.Task DeleteTask(int id)
        {
            using (var taskManagerDbContext = new TaskManagerDbContext())
            {
                var deletedTask = await GetTaskById(id);

                taskManagerDbContext.Tasks.Remove(deletedTask);
                await taskManagerDbContext.SaveChangesAsync();
            }
        }
Exemplo n.º 6
0
        public async System.Threading.Tasks.Task <Task> UpdateTask(Task task)
        {
            using (var taskManagerDbContext = new TaskManagerDbContext())
            {
                taskManagerDbContext.Tasks.Update(task);
                await taskManagerDbContext.SaveChangesAsync();

                return(task);
            }
        }
Exemplo n.º 7
0
 public async Task <IActionResult> Create(Task task)
 {
     if (ModelState.IsValid)
     {
         task.Id = 0;
         task.DateOfRegistration = DateTime.Now;
         task.TaskStatus         = TaskStatus.Appointed;
         _context.Add(task);
         await _context.SaveChangesAsync();
     }
     return(RedirectToAction("Index", new { selectedTaskId = task.Id }));
 }
Exemplo n.º 8
0
        public async Task <IActionResult> Post([FromBody] RegistrationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <AppUser>(model);

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }

            await _taskManagerContext.Customers.AddAsync(new Customer { IdentityId = userIdentity.Id });

            await _taskManagerContext.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
Exemplo n.º 9
0
 public Task <int> Save() => _context.SaveChangesAsync();
Exemplo n.º 10
0
 public async Task <bool> SaveChangesAsync()
 {
     return(await _context.SaveChangesAsync() >= 0);
 }
Exemplo n.º 11
0
 public async Task Add(T entity)
 {
     _context.Set <T>().Add(entity);
     await _context.SaveChangesAsync();
 }