public async Task <bool> SaveAsync(Owner obj) { _ = obj ?? throw new ArgumentNullException(); if (!(_context.Owners.Any(x => x.Id == obj.Id))) { _context.Add(obj); } foreach (var prop in obj.Properties) { switch (prop.EntityState) { case customEnums.EntityState.Added: _context.Entry(prop).State = efcore.EntityState.Added; break; case customEnums.EntityState.Modified: _context.Entry(prop).State = efcore.EntityState.Modified; break; case customEnums.EntityState.Deleted: _context.Entry(prop).State = efcore.EntityState.Deleted; break; default: break; } } var DbResponse = await Uow.SaveChangesAsync(default(CancellationToken)); return(DbResponse != 0); }
public UserModel AddUser(User user) { _userContext.Add(user); _userContext.SaveChanges(); var userModel = Map(user); return(userModel); }
public async Task<IActionResult> Create([Bind("Id,Price,Address,City,Zip,YearBuilt,PropertyType,SquareFeet,Bedrooms,Bathrooms,GarageCapacity,RelatorName,RelatorPhone,RelatorEmail")] Property @property) { if (ModelState.IsValid) { _context.Add(@property); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(@property); }
public async Task CreateRequestForCommandAsync <T>(Guid id) { var exists = await ExistAsync(id); var request = exists ? throw new PropertyDomainException($"Request with {id} already exists") : new ClientRequest() { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add(request); await _context.SaveChangesAsync(); }
public async Task <bool> Handle(CreateRoomInfoCommand message) { // Add/Update the Buyer AggregateRoot // DDD patterns comment: Add child entities and value-objects through the Order Aggregate-Root // methods and constructor so validations, invariants and business logic // make sure that consistency is preserved across the whole aggregate string number = message.RoomInfo.RoomNumber; RoomType type = message.RoomInfo.RoomType; BedType bedType = message.RoomInfo.BedType; RoomLocation location = message.RoomInfo.RoomLocation; var room = RoomInfo.Create(number, type, bedType, location); _propertyContext.Add(room); return(await _propertyContext.SaveEntitiesAsync()); }