Exemple #1
0
        public static string K1(string companyName, string middlemanName)
        {
            int idCompany, idMiddleman, idCompanyMiddleman;

            try
            {
                idCompany          = CompanyDataManipulation.GetId(companyName);
                idMiddleman        = MiddlemanDataManipulation.GetId(middlemanName);
                idCompanyMiddleman = CompanyMiddlemanDataManipulation.GetId(companyName, middlemanName);
            }
            catch
            {
                responseToClient.responseType = ResponseType.Bad;
                responseToClient.responseText = "Виникли проблеми з отриманням даних.";
                return(js.Serialize(responseToClient));
            }

            List <K1>            K1Records = K1DataManipulation.GetMulti(idCompanyMiddleman);
            List <TableK1ToSend> K1Table   = new List <TableK1ToSend>();

            //Uncomment for auto generate conditions
            //ConditionGeneration.K1(idCompanyMiddleman);
            //K1Records = K1DataManipulation.GetMulti(idCompanyMiddleman);

            foreach (var k in K1Records)
            {
                TableK1ToSend tempTableRow = new TableK1ToSend();
                tempTableRow.InsuranceTypeOfCar = db.CarInsuranceTypes.Where(cit => cit.Id == k.IdCarInsuranceType).Select(cit => cit.Type).FirstOrDefault();
                tempTableRow.Value = k.Value;
                K1Table.Add(tempTableRow);
            }

            List <TitlesToSend> titles = new List <TitlesToSend>();

            titles.Add(FillTitleToSend(name: "InsuranceTypeOfCar", titleUkr: "Тип транспорту", titleRus: "Тип транспорта"));
            titles.Add(FillTitleToSend(name: "Value", titleUkr: "Значення", titleRus: "Значение"));

            Dictionary <string, object> dataToSend = new Dictionary <string, object>();

            dataToSend.Add("titles", titles);
            dataToSend.Add("data", K1Table);

            return(js.Serialize(dataToSend));
        }
Exemple #2
0
        static public string K1(int idCompanyMiddleman)
        {
            List <CarInsuranceType> carInsuranceTypes = CarInsuranceTypeDataManipulation.GetMulti();

            if (carInsuranceTypes == null)
            {
                responseToClient.responseType = ResponseType.Bad;
                responseToClient.responseText = "Не знайдено умови \"Тип транспорту\"";
                return(js.Serialize(responseToClient));
            }

            foreach (var cit in carInsuranceTypes)
            {
                if (K1DataManipulation.IsConditionExist(cit, idCompanyMiddleman))
                {
                    var newRowK1 = new K1()
                    {
                        IdCarInsuranceType = cit.Id,
                        Value = 0,
                        IdCompanyMiddleman = idCompanyMiddleman,
                    };

                    try
                    {
                        K1DataManipulation.Insert(newRowK1);
                    }
                    catch
                    {
                        responseToClient.responseType = ResponseType.Bad;
                        responseToClient.responseText = $"Виникла помилка при генерації запису для умови \"{cit.Type}\"";
                        return(js.Serialize(responseToClient));
                    }
                }
            }

            responseToClient.responseType = ResponseType.Good;
            responseToClient.responseText = "Генерація даних пройшла успішно.";
            return(js.Serialize(responseToClient));
        }