public async Task <Service> Post(Service service) { if (ModelState.IsValid) { await ServiceService.AddAsync(service); } return(service); }
protected async Task HandleSubmit() { if (ServiceEditContext.Validate()) { var service = (await ServiceService.GetAsync( x => x.ServiceTypeId == AdminServiceVM.SelectedService && x.ServiceTypeDate.Equals(AdminServiceVM.Date), null, "ServiceType")) .FirstOrDefault(); if (service == null) { service = new Data.Service { Price = (decimal)AdminServiceVM.Price, ServiceTypeDate = (DateTime)AdminServiceVM.Date, IsActive = true }; if (AdminServiceVM.SelectedService > 0) { service.ServiceTypeId = AdminServiceVM.SelectedService; var oldService = (await ServiceService.GetAsync( x => x.ServiceTypeId == AdminServiceVM.SelectedService && x.IsActive, null, "ServiceType")) .FirstOrDefault(); if (oldService != null) { oldService.IsActive = false; ServiceService.Update(oldService); } } else { service.ServiceType = new Data.ServiceType { Name = AdminServiceVM.ServiceName, Description = AdminServiceVM.Description }; } await ServiceService.AddAsync(service); } else { service.Price = (decimal)AdminServiceVM.Price; ServiceService.Update(service); } await ServiceService.SaveChangesAsync(AppUser.Instance.FullName); await TableInitialiser(); ToggleView(); } await InvokeAsync(StateHasChanged); }
public async Task AddService_ReturnsAddedItem( [Frozen] Service testService) { // Arrange _wrapper.Setup(s => s.ServiceRepository.Add(It.IsAny <Service>())); // Act var result = await _serviceService.AddAsync(testService); // Assert Assert.IsType <Service>(result); Assert.Equal(testService, result); }