async public Task <InsuranceContent> AddContent(InsuranceContentRequest content) { InsuranceContent newContent; InsuranceCategory category; if (!CategoriesExists(content.CategoryId, content.CategoryName)) { category = new InsuranceCategory() { CategoryName = content.CategoryName }; _db.Categories.Add(category); } else { category = await _db.Categories.Where(x => x.Id == content.CategoryId || x.CategoryName == content.CategoryName).FirstAsync(); } newContent = new InsuranceContent { ContentDescription = content.ContentDescription, ContentValue = content.ContentValue, Category = category, CategoryId = category.Id }; _db.Contents.Add(newContent); await _db.SaveChangesAsync(); return(newContent); }
private void submit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(insuranceCaseNameInput.Text) || paymentProcentInput.Value == 0 || insurancePoliceDropDown.SelectedItem == null) { resultLabel.Text = "Проверьте заполнение всех полей."; } else { InsuranceCase insuranceCase = new InsuranceCase(); insuranceCase.InsuranceCaseName = insuranceCaseNameInput.Text; insuranceCase.PaymentProcent = paymentProcentInput.Value; InsuranceCategory category = (InsuranceCategory)insurancePoliceDropDown.SelectedItem; insuranceCase.InsuranceCategory = category; RegisterNewInsuranceCaseCommand command = new RegisterNewInsuranceCaseCommand(); bool result = command.registerNewInsuranceCase(insuranceCase); if (result == true) { insuranceCaseNameInput.Clear(); insurancePoliceDropDown.ResetText(); paymentProcentInput.ResetText(); resultLabel.Text = "Новый страховой случай успешно зарегистрирован."; } if (result == false) { resultLabel.Text = "Не удалось зарегистрировать новый страховой случай."; } } }