public async Task <IActionResult> PutDownloadSection([FromRoute] int id, [FromBody] DownloadSection downloadSection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != downloadSection.Id) { return(BadRequest()); } _context.Entry(downloadSection).State = EntityState.Modified; foreach (var p in downloadSection.Paragraphs) { _context.Entry(p).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DownloadSectionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostDownloadSection([FromBody] DownloadSection downloadSection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.DownloadSections.Add(downloadSection); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDownloadSection", new { id = downloadSection.Id }, downloadSection)); }
public async Task <IActionResult> PostWebsite([FromBody] Website website) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Websites.Add(website); Website newWebsite = new Website() { Id = website.Id, Name = website.Name, WebsiteUrl = website.WebsiteUrl }; HomeSection newhome = new HomeSection() { Header = website.Name + "Head", // BackgroundImageUrl = website.Name + "bg url", Paragraphs = new List <Paragraph>() { new Paragraph() { Text = "Home Para 1" }, new Paragraph() { Text = "Home Para 2" } }, WebsiteId = website.Id, isActive = true }; _context.HomeSections.Add(newhome); AboutSection newabout = new AboutSection() { Header = website.Name + " about", Paragraphs = new List <Paragraph>() { new Paragraph() { Text = "about Para 1" }, new Paragraph() { Text = "about Para 2" } }, WebsiteId = website.Id, isActive = true }; _context.AboutSections.Add(newabout); DownloadSection newdownload = new DownloadSection() { Header = website.Name + " download", BackgroundImageUrl = "assets/img/downloads-bg.jpg", Paragraphs = new List <Paragraph>() { new Paragraph() { Text = "download Para 1" }, new Paragraph() { Text = "download Para 2" } }, WebsiteId = website.Id, isActive = true }; _context.DownloadSections.Add(newdownload); ContactUsSection newcontactus = new ContactUsSection() { Header = website.Name + " contactus", Paragraphs = new List <Paragraph>() { new Paragraph() { Text = "contactus Para 1" } }, WebsiteId = website.Id, isActive = true }; _context.ContactUsSections.Add(newcontactus); List <SocialPortal> socials = new List <SocialPortal>() { new SocialPortal() { SocialTypeId = 1, url = "facebook url", ContactUsId = newcontactus.Id } }; newcontactus.SocialPortals = socials; //website.home = newhome; await _context.SaveChangesAsync(); CreatedAtActionResult car = CreatedAtAction("GetWebsite", new { id = newWebsite.Id }, newWebsite); return(car); //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} //_context.Websites.Add(website); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetWebsite", new { id = website.Id }, website); }