Ejemplo n.º 1
0
        public string UpdateHtmlFragment(HtmlFragment entity, int blogId, string selectedLocationId)
        {
            if (entity == null) return "The html fragment object to be updated was not provided";
            var blog = _context.Blogs.Find(blogId);
            if (blog == null) return "The parent blog for the html fragment to be updated was not found.";

            int locationId;
            if (!int.TryParse(selectedLocationId, out locationId))
                locationId = 0;

            var location = _context.HtmlFragmentLocations.Find(locationId);
            var htmlFragment = blog.HtmlFragments.FirstOrDefault(x => x.Id == entity.Id);
            if (htmlFragment == null) return "The specifed html fragment was not found.";
            htmlFragment.Location = location;
            htmlFragment.Name = entity.Name;
            htmlFragment.ScriptBody = entity.ScriptBody;
            _context.SaveChanges();
            _context.Dispose();
            return string.Empty;
        }
Ejemplo n.º 2
0
        public string AddHtmlFragment(HtmlFragment entity, int blogId, string selectedLocationId)
        {
            if (entity == null) return "The entity was not provided.";

            Blog blog = _context.Blogs.Find(blogId);
            if (blog == null) return "the specified blog was not found.";

            int locationId;
            if (!int.TryParse(selectedLocationId,out locationId)) locationId = 0;

            HtmlFragmentLocation location = _context.HtmlFragmentLocations.Find(locationId);
            if (location == null) return "The specified web page location was not found.";

            entity.Location = location;

            if (blog.HtmlFragments == null) blog.HtmlFragments = new Collection<HtmlFragment>();
            blog.HtmlFragments.Add(entity);
            _context.SaveChanges();
            _context.Dispose();
            return string.Empty;
        }
Ejemplo n.º 3
0
 public HtmlFragmentViewModel MapToView(HtmlFragment entity)
 {
     return Mapper.Map<HtmlFragment,HtmlFragmentViewModel >(entity);
 }