Beispiel #1
0
        public static HomeContentViewModel GetHomeContent()
        {
            try
            {
                using (var dc = new PortfolioDataContext())
                {
                    var homeContent = dc.PageContents.FirstOrDefault(i => i.ContentType == (int)MenuType.Index);

                    if (homeContent == null)
                    {
                        var content = new HomeContentViewModel()
                        {
                            Greeting = "Hi, I am Alex",
                            Intro    = "Software Developer"
                        };

                        return(CreateHomeContent(content));
                    }
                    else
                    {
                        return(JsonConvert.DeserializeObject <HomeContentViewModel>(homeContent.Content));
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #2
0
        public static HomeContentViewModel UpdateHomeContent(HomeContentViewModel content)
        {
            try
            {
                using (var dc = new PortfolioDataContext())
                {
                    var homeContent = dc.PageContents.FirstOrDefault(i => i.ContentType == (int)MenuType.Index);

                    if (homeContent == null)
                    {
                        return(null);
                    }
                    else
                    {
                        homeContent.Content = JsonConvert.SerializeObject(content);
                        dc.SubmitChanges();
                        return(content);
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #3
0
        public async Task <JsonResult> UpdateHome(HomeContentViewModel homeContent)
        {
            var     content = DBHelper.UpdateHomeContent(homeContent);
            dynamic respond = new ExpandoObject();

            respond.result   = "success";
            respond.greeting = content.Greeting;
            respond.intro    = content.Intro;
            respond.error    = "";

            return(Json(JsonConvert.SerializeObject(respond)));
        }
Beispiel #4
0
        private static HomeContentViewModel CreateHomeContent(HomeContentViewModel content)
        {
            try
            {
                using (var db = new PortfolioDataContext())
                {
                    db.PageContents.InsertOnSubmit(new PageContent()
                    {
                        ContentType = (int)MenuType.Index,
                        Content     = JsonConvert.SerializeObject(content)
                    });
                    db.SubmitChanges();

                    return(content);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }