public async Task <ActionResult> AddSection(AddSectionNameModel model) { if (ModelState.IsValid) { var result = await sectionService.AddSection(model); if (result) { return(Ok()); } else { ModelState.AddModelError("error", "Секция с таким именем уже существует"); } } return(BadRequest(ModelState)); }
public async Task <bool> AddSection(AddSectionNameModel model) { var SectionName = await context .SectionsNames .FirstOrDefaultAsync(sn => sn.SectionName == model.SectionName); if (SectionName == null) { await context .SectionsNames .AddAsync(new SectionsName { SectionName = model.SectionName }); await context.SaveChangesAsync(); return(true); } return(false); }
public async Task <ActionResult> AddSection(AddSectionNameModel model) { if (ModelState.IsValid) { var SectionName = context.SectionsNames.FirstOrDefault(sn => sn.SectionName == model.SectionName); if (SectionName == null) { await context .SectionsNames .AddAsync(new SectionsName { SectionName = model.SectionName }); await context.SaveChangesAsync(); return(Ok()); } else { ModelState.AddModelError("error", "Секция с таким именем уже существует"); } } return(BadRequest(ModelState)); }