Example #1
0
        public ChannelDetailsViewModel GetChannelById(int modelChannelId)
        {
            var channel = this.context.Channels.FirstOrDefault(ch => ch.Id == modelChannelId);

            var model = new ChannelDetailsViewModel();

            model.Description = channel.Description;
            model.Name        = channel.Name;
            model.Tags        = channel.Tags;
            model.Type        = channel.Type.ToString();
            model.Followers   = this.context.UsersChannels.Count(uc => uc.ChannelId == modelChannelId);

            return(model);
        }
Example #2
0
        public void CreateChannel(ChannelDetailsViewModel model)
        {
            var channel = new Channel
            {
                Name        = model.Name,
                Description = model.Description,
                Tags        = model.Tags,
                Type        = (ChannelType)Enum.Parse(typeof(ChannelType), model.Type, true)
            };

            this.context.Channels.Add(channel);

            this.context.SaveChanges();
        }
Example #3
0
        public IActionResult Details(int id)
        {
            ChannelDetailsViewModel model = this.channelService.GetChannel(id);

            if (model == null)
            {
                return(this.RedirectToAction("/"));
            }

            this.Model["Name"]           = model.Name;
            this.Model["Description"]    = model.Description;
            this.Model["Type"]           = model.Type;
            this.Model["Tags"]           = model.Tags;
            this.Model["FollowersCount"] = model.FollowersCount;

            return(this.View());
        }
        public ChannelDetailsViewModel GetChannel(int id)
        {
            using (var db = new MishMashDbContext())
            {
                ChannelDetailsViewModel model = db.Channels.Where(c => c.Id == id)
                                                .Select(c => new ChannelDetailsViewModel
                {
                    Name           = c.Name,
                    Description    = c.Description,
                    Tags           = string.Join(", ", c.Tags.Select(ct => ct.Tag.Name)),
                    Type           = c.Type.ToString(),
                    FollowersCount = c.Followers.Count()
                })
                                                .FirstOrDefault();

                return(model);
            }
        }
        public void AddChannel(ChannelDetailsViewModel model)
        {
            using (var db = new MishMashDbContext())
            {
                var channel = new Channel
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Type        = Enum.Parse <ChannelType>(model.Type)
                };

                if (!string.IsNullOrWhiteSpace(model.Tags))
                {
                    string[] tags = model.Tags.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (string tag in tags)
                    {
                        Tag dbTag = db.Tags.FirstOrDefault(t => t.Name == tag);

                        if (dbTag == null)
                        {
                            dbTag = new Tag {
                                Name = tag
                            };

                            db.Tags.Add(dbTag);
                            db.SaveChanges();
                        }

                        channel.Tags.Add(new TagChannel {
                            TagId = dbTag.Id
                        });
                    }
                }

                db.Channels.Add(channel);
                db.SaveChanges();
            }
        }
Example #6
0
        public IActionResult Create(ChannelDetailsViewModel model)
        {
            this.channelService.AddChannel(model);

            return(this.RedirectToAction("/"));
        }