public async Task <IActionResult> PostContactUsSection([FromBody] ContactUsSection contactUsSection)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ContactUsSections.Add(contactUsSection);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetContactUsSection", new { id = contactUsSection.Id }, contactUsSection));
        }
        public async Task <IActionResult> PutContactUsSection([FromRoute] int id, [FromBody] ContactUsSection contactUsSection)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contactUsSection.Id)
            {
                return(BadRequest());
            }

            _context.Entry(contactUsSection).State = EntityState.Modified;
            foreach (var p in contactUsSection.Paragraphs)
            {
                _context.Entry(p).State = EntityState.Modified;
            }
            foreach (var p in contactUsSection.SocialPortals)
            {
                _context.Entry(p).State = EntityState.Modified;
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContactUsSectionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        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);
        }