public static ChannelResource UpdateWith(this ChannelResource resource, ProjectChannel model, ProjectResource projectResource)
 {
     resource.Name        = model.Identifier.Name;
     resource.Description = model.Description;
     resource.IsDefault   = model.IsDefault;
     resource.ProjectId   = projectResource.Id;
     return(resource);
 }
Ejemplo n.º 2
0
 public static YamlProjectChannel FromModel(ProjectChannel model)
 {
     return(new YamlProjectChannel
     {
         Name = model.Identifier.Name,
         Description = model.Description,
         IsDefault = model.IsDefault
     });
 }
Ejemplo n.º 3
0
        public string CreateChannel(Message message)
        {
            try
            {
                List <Channel> messageChannels = new List <Channel>(message.Fields.Channels.OfType <Channel>());

                Project dbEntry = Context.Projects.Find(messageChannels[0].Id);

                if (dbEntry == null)
                {
                    try
                    {
                        var p = new Channel
                        {
                            Title     = messageChannels[0].Title,
                            ProjectId = messageChannels[0].ProjectId,
                        };

                        Context.Channels.Add(p);
                        Context.SaveChanges();


                        var pc = new ProjectChannel
                        {
                            ProjectId = p.ProjectId,
                            ChannelId = (from x in Context.Channels
                                         where x.Title == p.Title
                                         select x.Id).FirstOrDefault()
                        };

                        Context.ProjectChannels.Add(pc);

                        Context.SaveChanges();

                        var project = (from x in Context.Projects
                                       where x.Id == p.ProjectId
                                       select x).FirstOrDefault();

                        var admin = (from x in Context.Users
                                     where x.Username == project.OwnerUsername
                                     select x).FirstOrDefault();

                        var cu = new ChannelUser
                        {
                            ChannelId = (from x in Context.Channels
                                         where x.Title == p.Title
                                         select x.Id).FirstOrDefault(),
                            Username = admin.Username
                        };

                        Context.ChannelUser.Add(cu);
                        Context.SaveChanges();

                        return(JsonConvert.SerializeObject(new Message("channel", "create", 201, "Channel created")));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        return(JsonConvert.SerializeObject(new Message("channel", "create", 500, "Bad request")));
                    }
                }

                return(JsonConvert.SerializeObject(new Message("channel", "create", 200, "Channel exists")));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(JsonConvert.SerializeObject(new Message("channel", "create", 500, e.Message)));
            }
        }