public Order toOrder() { // Jeśli którekolwiek TryParse zwróci false !false=true if (!double.TryParse(Price, out double price) || !long.TryParse(RequestId, out long requestId) || !int.TryParse(Quantity, out int quantity)) { return(null); } // Zapobieganie niechcianym formatom danym - wytyczne przedstawione w poleceniu if (ClientId == null || RequestId == null || Name == null || Quantity == null || Price == null) { return(null); } if (Name.Length > 255) { return(null); } if (ClientId.Equals("") || Name.Equals("")) { return(null); } if (ClientId.Length > 6 || ClientId.Contains(" ")) { return(null); } //Zwracamy objekt wywołując konstruktor parametryczny return(new Order(ClientId, requestId, Name, quantity, price)); }
public List <string> Validate() { var errors = new List <string>(); if (string.IsNullOrEmpty(ClientId)) { errors.Add("ClientId is empty"); } else if (ClientId.Length > 6) { errors.Add("ClientId is longer then 6 chars"); } else if (ClientId.Contains(" ")) { errors.Add("ClientId contains spaces"); } if (RequestId == null) { errors.Add("RequestId is not a long"); } if (string.IsNullOrEmpty(Name)) { errors.Add("Name is empty"); } else if (Name.Length > 255) { errors.Add("Name is longer then 255 chars"); } if (Quantity == null) { errors.Add("Quantity is not an int"); } if (Price == null) { errors.Add("Price is not a double"); } return(errors); }
public List <string> Validate() { var errors = new List <string>(); if (string.IsNullOrEmpty(ClientId)) { errors.Add("ClientId is empty"); } else if (ClientId.Length > 6) { errors.Add("ClientId is longer then 6 chars"); } else if (ClientId.Contains(" ")) { errors.Add("ClientId contains spaces"); } if (RequestId == null) { errors.Add("RequestId is not a long"); } return(errors); }