コード例 #1
0
        public async Task <ActionResult> UpdateSection(UpdateSectionModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await sectionService.UpdateSection(model);

                if (result)
                {
                    return(Ok());
                }
                return(NotFound());
            }
            return(BadRequest(ModelState));
        }
コード例 #2
0
ファイル: SectionService.cs プロジェクト: IdokkeI/News-App
        public async Task <bool> UpdateSection(UpdateSectionModel model)
        {
            var sectionName = await context
                              .SectionsNames
                              .FirstOrDefaultAsync(sn => sn.SectionName == model.OldName);

            if (sectionName == null)
            {
                return(false);
            }

            sectionName.SectionName = model.SectionName;
            context.SectionsNames.Update(sectionName);
            await context.SaveChangesAsync();

            return(true);
        }