Esempio n. 1
0
        public PostIndexModelPost(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title.ToString();

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Comments  = "0"; // todo: add comments table, and do a count of them here
            Timestamp = post.Timestamp.ToString();
        }
Esempio n. 2
0
        public static UserEditModel UserEdit(string id)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            if (id.IsNullOrWhiteSpace())
            {
                UserEditModel model = new UserEditModel(new Blog.User(), "Add");
                return(model);
            }
            else
            {
                Blog.User     user  = database.Users.FirstOrDefault(x => x.Id == new Guid(id));
                UserEditModel model = new UserEditModel(user, "Edit");
                return(model);
            }
        }
Esempio n. 3
0
 public UserEditModel(Blog.User user, string addOrEdit)
 {
     Id             = user.Id;
     Username       = user.Username;
     Email          = user.Email;
     Role           = user.Role;
     FirstName      = user.FirstName;
     LastName       = user.LastName;
     Nickname       = user.Nickname;
     PublicName     = user.PublicName;
     Website        = user.Website;
     Biography      = user.Biography;
     ProfilePicture = user.ProfilePicture;
     Password       = user.Password;
     AddOrEdit      = addOrEdit;
 }
Esempio n. 4
0
        public static Blog.User UserEditPost(UserEditModel model)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Blog.User databaseModel = database.Users.FirstOrDefault(x => x.Id == model.Id);

            if (databaseModel != null)
            {
                databaseModel.Username       = model.Username;
                databaseModel.Email          = model.Email;
                databaseModel.Role           = model.Role;
                databaseModel.FirstName      = model.FirstName;
                databaseModel.LastName       = model.LastName;
                databaseModel.Nickname       = model.Nickname;
                databaseModel.PublicName     = model.PublicName;
                databaseModel.Website        = model.Website;
                databaseModel.Biography      = model.Biography;
                databaseModel.ProfilePicture = model.ProfilePicture;
                databaseModel.Password       = model.Password;
            }
            else
            {
                databaseModel = new Blog.User();

                databaseModel.Id = Guid.NewGuid();

                databaseModel.Username       = model.Username;
                databaseModel.Email          = model.Email;
                databaseModel.Role           = model.Role;
                databaseModel.FirstName      = model.FirstName;
                databaseModel.LastName       = model.LastName;
                databaseModel.Nickname       = model.Nickname;
                databaseModel.PublicName     = model.PublicName;
                databaseModel.Website        = model.Website;
                databaseModel.Biography      = model.Biography;
                databaseModel.ProfilePicture = model.ProfilePicture;
                databaseModel.Password       = model.Password;

                database.Users.InsertOnSubmit(databaseModel);
            }
            database.SubmitChanges();

            return(databaseModel);
        }
Esempio n. 5
0
        // todo: comments list

        public PostViewModel(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title;
            Body  = post.Body;

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Timestamp       = post.Timestamp.ToString();
            CommentsEnabled = post.CommentsEnabled;
            Status          = post.Status;
            Visibility      = post.Visibility;
            Slug            = post.Slug;
        }