public async Task<Unit> Handle(BuyCowCommand request, CancellationToken cancellationToken) { var cowToBuy = Domain.Models.CowAggregate.Cow.FromBought(request.Price, request.Weight, request.DateOfBirth, request.EarningNumber); _context.Add(cowToBuy); await _context.SaveChangesAsync(cancellationToken); return Unit.Value; }
public async Task <Unit> Handle(NewCowshedCommand request, CancellationToken cancellationToken) { var newCowshed = new Domain.Models.CowAggregate.Cowshed(request.NumberOfPlaces, request.Name, request.DateOfBuild); _context.Add(newCowshed); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(NewCowCommand request, CancellationToken cancellationToken) { var newCow = new Cow(request.EarningNumber, request.DateOfBirth, request.PassportNumber, request.CowshedId); _context.Add(newCow); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <IActionResult> Save([Bind("Id,Title,Content,Slug")] CMS cms) { //var cms = _dbContext.CMSs.FirstOrDefault(x => x.Title == data.Title); if (ModelState.IsValid) { if (cms.Id == 0) { //return View("Error"); _dbContext.Add(cms); } else { _dbContext.Update(cms); } await _dbContext.SaveChangesAsync(); } return(RedirectToAction(nameof(ManageCMS))); }
public void Add(T entity) { context.Add(entity); context.SaveChanges(); }