public ActionResult Edit([Bind(Include = "Id,Name")] Country country) { CountryValidator validar = new CountryValidator(); ValidationResult Result = validar.Validate(country); if (!Result.IsValid) { foreach (ValidationFailure item in Result.Errors) { ModelState.AddModelError(item.PropertyName, item.ErrorMessage); } return(View(country)); } else { var objCountry = countryService.Actualizar(country); return(View(country)); } //if (ModelState.IsValid) //{ // db.Entry(country).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); //} //return View(country); }
public async Task <IActionResult> PutCountry(int id, Country country) { var _countriesService = new CountriesService(_context); if (id != country.Id) { return(BadRequest()); } var CountryValidater = new CountryValidator(); var resultValidation = CountryValidater.Validate(country); if (!resultValidation.IsValid) { return(BadRequest(resultValidation.Errors)); } var result = await _countriesService.PutCountry(id, country); if (result) { return(Ok()); } return(NoContent()); }
public OperationResult <bool> AddCustomer(Customers customer) { var result = new OperationResult <bool>(); try { if (!CountryValidator.Validate(customer.Country)) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = "Country code does not exists"; } else if (_customerRepo.Get(customer.CustomerId) != null) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = $"Customer: {customer.CustomerId} already exists"; } else { _customerRepo.Add(customer); var saveResult = _context.SaveChanges(); result.Data = true; result.Status = eOperationStatus.Success; } } catch (Exception ex) { result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = ex.Message; result.Data = false; } return(result); }
public void CountryValidator() { var v = new CountryValidator(PropertyName, Description); AssertValidatorProperties(v); var o = new SimpleObject(); Assert.IsTrue(v.Validate(o)); o.SimpleProperty = string.Empty; Assert.IsTrue(v.Validate(o)); o.SimpleProperty = "IT"; Assert.IsTrue(v.Validate(o)); o.SimpleProperty = "XX"; Assert.IsFalse(v.Validate(o)); }
private static void ValidateCountry(string country) { var validator = new CountryValidator(); var result = validator.Validate(country); if (!result.IsValid) { throw new IdentityDomainException(nameof(country)); } }
public OperationResult <bool> AddAddress(string id, Addresses address) { var result = new OperationResult <bool>(); try { var customer = _customerRepo.Get(id); if (customer != null) { if (!CountryValidator.Validate(address.Country)) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = "Country code does not exists"; } else if (_addrRepo.Get(address.AddressId) != null) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = $"Address:{address.AddressId} already exists"; } else { address.CustomerId = id; _addrRepo.Add(address); var saveResult = _context.SaveChanges(); if (saveResult > 0) { result.Data = true; result.Status = eOperationStatus.Success; } else { result.Data = false; result.Status = eOperationStatus.GeneralError; } } } else { result.Data = false; result.Status = eOperationStatus.NotFound; result.ExceptionMessage = "Customer not found"; } } catch (Exception ex) { result.Data = false; result.ExceptionMessage = ex.Message; result.Status = eOperationStatus.GeneralError; } return(result); }
public async Task <ActionResult <Country> > PostCountry(Country country) { var validator = new CountryValidator(); var resultValid = validator.Validate(country); if (!resultValid.IsValid) { return(BadRequest(resultValid.Errors)); } var result = _countriesService.Add(country); return(CreatedAtAction("GetCountry", new { id = result.Id }, result)); }
public string this[string columnName] { get { var result = _validator.Validate(Mapper.Map <Country>(this)); if (!result.Errors.Any(e => e.PropertyName == columnName)) { return(string.Empty); } var error = result.Errors .First(e => e.PropertyName == columnName) .ErrorMessage; return(error); } }
public OperationResult <bool> UpdateCustomer(Customers customer) { var result = new OperationResult <bool>(); try { if (!CountryValidator.Validate(customer.Country)) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = "Country code does not exists"; } else { var toUpdate = _customerRepo.Get(customer.CustomerId); toUpdate.Addresses = customer.Addresses; toUpdate.City = customer.City; toUpdate.Country = customer.Country; toUpdate.Name = customer.Name; toUpdate.Street = customer.Street; toUpdate.Zip = customer.Zip; var saveResult = _context.SaveChanges(); if (saveResult > 0) { result.Data = true; result.Status = eOperationStatus.Success; } else { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = "Could not update Customer"; } } } catch (Exception ex) { result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = ex.Message; result.Data = false; } return(result); }
public ActionResult Create([Bind(Include = "Id,Name")] Country country) { CountryValidator validar = new CountryValidator(); ValidationResult Result = validar.Validate(country); if (!Result.IsValid) { foreach (ValidationFailure item in Result.Errors) { ModelState.AddModelError(item.PropertyName, item.ErrorMessage); } return(View(country)); } else { var objCountry = countryService.Insertar(country); return(RedirectToAction("Index")); } }
public ResponseBase <TBL_SLI_COUNTRY> Insert(TBL_SLI_COUNTRY country) { CountryValidator validator; try { validator = new CountryValidator(); _results = validator.Validate(country); if (_results.IsValid) { country.BIT_STATE = true; country.VCH_NAME = country.VCH_NAME.ToUpper(); var countryFound = _context.TBL_SLI_COUNTRY.Where(x => x.VCH_NAME.Contains(country.VCH_NAME)).FirstOrDefault(); _response = new UtilityResponse <TBL_SLI_COUNTRY>().SetResponseBaseForUniqueValidation(); if (countryFound == null) { _context.TBL_SLI_COUNTRY.Add(country); _context.SaveChanges(); _response = new UtilityResponse <TBL_SLI_COUNTRY>().SetResponseBaseForObj(country); } } else { _response = new UtilityResponse <TBL_SLI_COUNTRY>().SetResponseBaseFunctionalErrors(_results); } return(_response); } catch (Exception ex) { _response = new UtilityResponse <TBL_SLI_COUNTRY>().SetResponseBaseForException(ex); return(_response); } finally { _response = null; _results = null; validator = null; _context.Database.Connection.Close(); } }
public OperationResult <bool> UpdateAddress(string id, Addresses address) { var result = new OperationResult <bool>(); try { var customer = _customerRepo.Get(id); if (customer != null) { if (!CountryValidator.Validate(address.Country)) { result.Data = false; result.Status = eOperationStatus.GeneralError; result.ExceptionMessage = "Country code does not exists"; } else { var addressToUpdate = _addrRepo.Get(address.AddressId); if (addressToUpdate != null && addressToUpdate.CustomerId == id) { addressToUpdate.AddressType = address.AddressType; addressToUpdate.City = address.City; addressToUpdate.Country = address.Country; addressToUpdate.Name = address.Name; addressToUpdate.Street = address.Street; addressToUpdate.Zip = address.Zip; var saveResult = _context.SaveChanges(); if (saveResult > 0) { result.Data = true; result.Status = eOperationStatus.Success; } else { result.Data = false; result.Status = eOperationStatus.GeneralError; } } else { result.Data = false; result.Status = eOperationStatus.NotFound; result.ExceptionMessage = "Address not found"; } } } else { result.Data = false; result.Status = eOperationStatus.NotFound; result.ExceptionMessage = "Customer not found"; } } catch (Exception ex) { result.Data = false; result.ExceptionMessage = ex.Message; result.Status = eOperationStatus.GeneralError; } return(result); }