using AutoServiceSultik; using AutoServiceSultik.Entites; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace ServiceUnitTest { public static class ServiceValidationTestingMethod { private static Service[] Services = new Service[2] { new Service() { Title = "Замена жидкости в кондиционере", Cost = 3040, DurationInSeconds = 28800}, new Service() { Title = "Ремонт и замена коллектора", Cost = 2770, DurationInSeconds = 9000, Discount = 0.15} }; public static string CheckErrors(string name, string costStr, string discountStr) { var errorBuider = new StringBuilder(); if (string.IsNullOrEmpty(name)) errorBuider.AppendLine("Название услуги обязательно для заполнения;"); var serviceFromDB = Services.FirstOrDefault(p => p.Title.ToLower() == name.ToLower()); if (serviceFromDB != null) errorBuider.AppendLine("Такая услуга уже существует;"); decimal cost = 0; if (decimal.TryParse(costStr, out cost) == false || cost <= 0) errorBuider.AppendLine("Стоимость услуги должно быть положительное число;"); if (!string.IsNullOrEmpty(discountStr)) { int discoutn = 0; if (int.TryParse(discountStr, out discoutn) == false || discoutn < 0 || discoutn > 100) errorBuider.AppendLine("Размер скидки - целое число в диапазоне от 0 до 100%"); } return errorBuider.ToString(); } } }