private async Task Save(Payload <IPayload> payload) { await ResilientTransaction.New(_context).ExecuteAsync(async() => { _context.Apartment.Add(payload.Apartment); await _context.SaveChangesAsync(); payload.InObject.ApartmentId = payload.Apartment.Id; _context.Add(payload.InObject); await _context.SaveChangesAsync(); }); }
public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,Email,PhoneNumber,EnrollmentDate,Street,City,Zip")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("ID,MaintenanceFees,Title,Price,SuitesNumber,Size,Cep,City,District,PhoneNumber,ParkingSpace,Leasing,Sale")] Apartment apartment) { if (ModelState.IsValid) { _context.Add(apartment); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(apartment)); }
public async Task <IActionResult> Create([Bind("FirstName,LastName,Phone,Email")] Tenant tenant) { if (ModelState.IsValid) { _context.Add(tenant); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(tenant)); }
public async Task <IActionResult> Create([Bind("ApartmentId,AptAddress,SqFootage,MonthUtilityFee,MonthParkfee,LastCleanDate,IsVacant")] Apartment apartment) { if (ModelState.IsValid) { _context.Add(apartment); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(apartment)); }
public async Task <IActionResult> Create([Bind("ApartmentID,Name,Garage,Shares")] Apartment apartment) { if (ModelState.IsValid) { _context.Add(apartment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(apartment)); }
public async Task <IActionResult> Create([Bind("UserApartmentID,UserID,ApartmentID,Owner,Resident")] UserApartment userApartment) { if (ModelState.IsValid) { _context.Add(userApartment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ApartmentID"] = new SelectList(_context.Apartments, "ApartmentID", "Name", userApartment.ApartmentID); ViewData["UserID"] = new SelectList(_context.Users, "ID", "LastName", userApartment.UserID); return(View(userApartment)); }
public async Task <IActionResult> Create([Bind("ContractId,StartDate,EndDate,MonthlyRent,ApartmentId,TenantId")] Contract contract) { if (ModelState.IsValid) { _context.Add(contract); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["ApartmentId"] = new SelectList(_context.Apartments, "ApartmentId", "ApartmentId", contract.ApartmentId); ViewData["TenantId"] = new SelectList(_context.Tenants, "TenantId", "TenantId", contract.TenantId); return(View(contract)); }
public async Task <IActionResult> Create([Bind("RoomId,RoomNo,RoomTypeId,Price,Area,Status")] Room room) { if (ModelState.IsValid) { _context.Add(room); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["RoomTypeId"] = new SelectList(_context.RoomType, "RoomTypeId", "RoomTypeName", room.RoomTypeId); return(View(room)); }
public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,BirthDay,IdentityCardNo,PhoneNo,Email,Gender,Status,DistrictId,ProvinceId")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } if (customer.ProvinceId != null) { ViewBag.Districts = new SelectList(_context.District.Where(x => x.ProvinceId == customer.ProvinceId), "DistrictId", "DistrictName"); } ViewData["ProvinceId"] = new SelectList(_context.Province, "ProvinceId", "ProvinceName", customer.ProvinceId); return(View(customer)); }
public async void DeleteOrderByIdAsync_PositiveAndNegative_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "DeleteOrderByIdAsync_PositiveAndNegative_TestAsync") .Options; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); Apartment apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var orderInBase = await context.Orders.AsNoTracking().FirstOrDefaultAsync(); var service = new OrderUserService(context, _mapper); var resultPositive = await service.DeleteOrderByIdAsync(orderInBase.Id.ToString(), orderInBase.CustomerId.ToString()); var resultNegative = await service.DeleteOrderByIdAsync(new Guid().ToString(), new Guid().ToString()); resultPositive.IsSuccess.Should().BeTrue(); resultPositive.Message.Should().BeNull(); resultNegative.IsSuccess.Should().BeFalse(); resultNegative.Message.Should().Contain("not found"); } }
public async void UpdateOrderAsync_Positive_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "UpdateOrderAsync_PositiveAndNegative_TestAsync") .Options; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); Apartment apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var service = new OrderUserService(context, _mapper); var orderInBase = await context.Orders.AsNoTracking().FirstOrDefaultAsync(); var orderForUpdate = _mapper.Map <OrderDTO>(orderInBase); DateTime newDate = new DateTime(DateTime.Now.Year + 1, DateTime.Now.Month, DateTime.Now.Day); IEnumerable <DateTime> dates = new List <DateTime>() { newDate }; orderForUpdate.Dates = dates; var resultPositive = await service.UpdateOrderAsync(orderForUpdate); resultPositive.IsSuccess.Should().BeTrue(); //resultPositive.Data.Order.Dates.FirstOrDefault().Should().BeSameDateAs(newDate); } }
public async void GetAllOrdersByApartmentIdAsync_PositiveAndNegative_TestAsync() { var options = new DbContextOptionsBuilder <ApartmentContext>() .UseInMemoryDatabase(databaseName: "GetAllOrdersByApartmentIdAsync_PositiveAndNegative_TestAsync") .Options; Apartment apartmentWithOrders; using (var context = new ApartmentContext(options)) { Country country = new Country() { Name = "Litva" }; context.Add(country); context.AddRange(_users); await context.SaveChangesAsync(); User userWithOrders = context.Users.AsNoTracking().FirstOrDefault(); foreach (var item in _addresses) { item.CountryId = context.Countries.FirstOrDefault().Id; } for (int i = 0; i < 2; i++) { _apartments[i].OwnerId = userWithOrders.Id; _apartments[i].Address = _addresses[i]; } context.AddRange(_apartments); await context.SaveChangesAsync(); apartmentWithOrders = context.Apartments.AsNoTracking().FirstOrDefault(); Order order = new Order() { ApartmentId = apartmentWithOrders.Id, CustomerId = userWithOrders.Id, }; List <BusyDate> busyDates = new List <BusyDate>(); BusyDate date = new BusyDate() { ApartmentId = apartmentWithOrders.Id, Date = DateTime.Now.Date }; busyDates.Add(date); order.Dates = _mapper.Map <HashSet <BusyDate> >(busyDates); context.AddRange(order); await context.SaveChangesAsync(); } using (var context = new ApartmentContext(options)) { var service = new OrderUserService(context, _mapper); var ordersInBase = await context.Orders.AsNoTracking().ToListAsync(); var apartmentWithoutOrders = await context.Users.Where(_ => _.Id != apartmentWithOrders.Id).FirstOrDefaultAsync(); var resultPositive = await service.GetAllOrdersByApartmentIdAsync(new Common.PagedRequest <string>(apartmentWithOrders.Id.ToString())); var resultNegative = await service.GetAllOrdersByApartmentIdAsync(new Common.PagedRequest <string>(apartmentWithoutOrders.Id.ToString())); foreach (var item in ordersInBase) { resultPositive.Data.Data.FirstOrDefault() .ApartmentId .Should().BeEquivalentTo(item.ApartmentId.ToString()); } resultNegative.Data.Data.Should().BeEmpty(); } }