public void WhenValueIsValid_ThenResultShouldBeEmpty() { var context = new PropertyValidatorContext(null, _propertyRule, null, "5544205163"); var result = _validator.Validate(context); result.Should().BeEmpty(); }
public Task HandleAsync(DeletePhoneCommand command) { var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]); var phone = _phoneRepository.Get(phoneId); PhoneValidator.Validate(phone, phone.Id); _phoneRepository.Delete(phone); return(Task.CompletedTask); }
public Task <PhoneQueryResponse> HandleAsync(PhoneQuery query) { var phone = _phoneRepository.Get(query.Id); PhoneValidator.Validate(phone, query.Id); _dimensionsRepository.Get(phone.Id); _displayRepository.Get(phone.Id); _mediaRepository.GetAll().Where(m => m.PhoneId == query.Id); var mapped = _mapper.Map <PhoneViewModel>(phone); return(Task.FromResult(new PhoneQueryResponse { Phone = mapped })); }
public Task HandleAsync(UpdatePhoneCommand command) { var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]); var phone = _phoneRepository.Get(phoneId); PhoneValidator.Validate(phone, phone.Id); phone.Name = command.Name; phone.Manufacturer = command.Manufacturer; phone.OS = command.OS; phone.Price = command.Price; phone.RAM = command.RAM; phone.Weight = command.Weight; phone.CPUModel = command.CPUModel; _phoneRepository.Update(phone); return(Task.CompletedTask); }
public async Task <IActionResult> Edit(int id, Phone phone) { if (id != phone.Id) { return(NotFound()); } List <ErrorMessage> errors = _phoneValidator.Validate(phone); CheckErrors(errors); if (!ModelState.IsValid) { return(View(GetEditModel(phone))); } try { phone = _context.Phones.FirstOrDefault(c => c.Id == id); phone.Name = "Edited name"; _context.Update(phone); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PhoneExists(phone.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); }
public Task HandleAsync(PhoneOrderCommand command) { var user = _usersRepository .GetAll() .Where(u => u.Email == _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.Email).Value) .FirstOrDefault(); var phone = _phoneRepository.Get(command.PhoneId); PhoneValidator.Validate(phone, command.PhoneId); var order = new Orders { AddedDate = DateTime.Now, CreditCardNumber = command.CreditCardNumber, NameOnCard = command.NameOnCard, User = user, PhoneId = phone.Id }; _ordersRepository.Insert(order); return(Task.CompletedTask); }