Пример #1
0
        public async Task <IActionResult> ChannelCreate()
        {
            var user = await GetCurrentUserAsync();

            ChannelCreateViewModel model = new ChannelCreateViewModel(context, user);

            return(View(model));
        }
Пример #2
0
        public IHttpResponse Create(ChannelCreateViewModel model)
        {
            if (!Enum.TryParse(model.Type, true, out Type type))
            {
                return(this.BadRequestErrorWithView("Invalid channelType"));
            }

            var channel = new Channel
            {
                Name        = model.Name,
                Description = model.Description,
                Type        = type
            };

            if (!string.IsNullOrWhiteSpace(model.Tags))
            {
                var tags = model.Tags.Split(',', ';', StringSplitOptions.RemoveEmptyEntries);

                foreach (var tag in tags)
                {
                    var dbTag = this.Db.Tags.FirstOrDefault(x => x.Name == tag.Trim());
                    if (dbTag == null)
                    {
                        dbTag = new Tag {
                            Name = tag.Trim()
                        };
                        this.Db.Tags.Add(dbTag);
                        this.Db.SaveChanges();
                    }

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

                Db.Channels.Add(channel);
                Db.SaveChanges();
            }

            return(this.Redirect("/"));
        }
Пример #3
0
        public async Task <IActionResult> ChannelCreate(PodcastChannel podcastchannel)
        {
            //Ignore user from model state
            // ModelState.Remove("podcastchannel.User");

            //This creates a new variable to hold our current instance of the ActiveCustomer class and then sets the active customer's id to the CustomerId property on the product being created so that a valid model is sent to the database
            var user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                // podcastchannel.User = user;
                context.Add(podcastchannel);
                await context.SaveChangesAsync();

                return(RedirectToAction("Create"));
            }

            ChannelCreateViewModel model = new ChannelCreateViewModel(context, user);

            return(View(model));
        }
Пример #4
0
 public IActionResult Create(ChannelCreateViewModel model)
 {
     this.channelService.AddChannel(model.Name, model.Description, model.Tags, model.Type);
     return(new RedirectResult("/"));
 }