public Address(ClientFullInfo clientFullInfo) { id = clientFullInfo.AddressId; Street = clientFullInfo.Street; PostName = clientFullInfo.PostName; PostNumber = clientFullInfo.PostNumber; Country = clientFullInfo.Country; }
public ClientFullInfo GetClientById(int id) { var client = _crud.GetEntityById <Client>(id); var address = _crud.GetEntityById <Address>(client.AddressId); ClientFullInfo result = new ClientFullInfo(client, address); return(result); }
public void DeleteClient(ClientFullInfo clientFullInfo) { var transaction = _crud.Context.Database.BeginTransaction(); Client client = new Client(clientFullInfo); Address address = new Address(clientFullInfo); try { _crud.DeleteEntity <Address>(address); _crud.DeleteEntity <Client>(client); transaction.Commit(); } catch { transaction.Rollback(); } }
public ClientFullInfo CreateClient(ClientFullInfo clientFullInfo) { var transaction = _crud.Context.Database.BeginTransaction(); Client client = new Client(clientFullInfo); Address address = new Address(clientFullInfo); try { var newAddress = _crud.CreateEntity <Address>(address); client.AddressId = newAddress.id; var newClient = _crud.CreateEntity <Client>(client); transaction.Commit(); return(new ClientFullInfo(newClient, newAddress)); } catch { transaction.Rollback(); return(new ClientFullInfo()); } }
public void DeleteClient(ClientFullInfo clientFullInfo) { List <RuleViolation> ruleViolations = new List <RuleViolation>(); if (clientFullInfo.id == 0) { ruleViolations.Add(new RuleViolation("Birth date cannot be null")); } if (ruleViolations.Count > 0) { throw new RuleViolationException(ruleViolations); } try { _clientRepository.DeleteClient(clientFullInfo); } catch (Exception ex) { ruleViolations.Add(new RuleViolation(ex)); throw new RuleViolationException(ruleViolations); } }
public void UpdateClient(ClientFullInfo clientFullInfo) { List <RuleViolation> ruleViolations = new List <RuleViolation>(); if (String.IsNullOrEmpty(clientFullInfo.FirstName)) { ruleViolations.Add(new RuleViolation("First name cannot be empty")); } if (String.IsNullOrEmpty(clientFullInfo.LastName)) { ruleViolations.Add(new RuleViolation("Last name cannot be empty")); } if (String.IsNullOrEmpty(clientFullInfo.Email)) { ruleViolations.Add(new RuleViolation("Email cannot be empty")); } if (String.IsNullOrEmpty(clientFullInfo.Country)) { ruleViolations.Add(new RuleViolation("Country cannot be empty")); } if (String.IsNullOrEmpty(clientFullInfo.PostName)) { ruleViolations.Add(new RuleViolation("Post name cannot be empty")); } if (String.IsNullOrEmpty(clientFullInfo.PostNumber)) { ruleViolations.Add(new RuleViolation("Post number cannot be empty")); } if (clientFullInfo.PostNumber.Length > 5) { ruleViolations.Add(new RuleViolation("Post number cannot be more than 5 digits")); } if (String.IsNullOrEmpty(clientFullInfo.Street)) { ruleViolations.Add(new RuleViolation("Street cannot be empty")); } if (clientFullInfo.BirthDate == null) { ruleViolations.Add(new RuleViolation("Birth date cannot be null")); } var isNumeric = int.TryParse(clientFullInfo.PostNumber, out _); if (!isNumeric) { ruleViolations.Add(new RuleViolation("Post number must be numeric")); } if (ruleViolations.Count > 0) { throw new RuleViolationException(ruleViolations); } try { _clientRepository.UpdateClient(clientFullInfo); } catch (Exception ex) { ruleViolations.Add(new RuleViolation(ex)); throw new RuleViolationException(ruleViolations); } }
public virtual IActionResult DeleteClient(ClientFullInfo clientFullInfo) { _clientService.DeleteClient(clientFullInfo); return(JsonData(new { })); }
public virtual IActionResult CreateClient(ClientFullInfo clientFullInfo) { var result = _clientService.CreateClient(clientFullInfo); return(JsonData(result)); }