public string Edit([FromForm] string json)
        {
            try {
                this.Request = new Request(json);
                HttpRequest httpRequest = HttpContext.Request;
                int         mediaType   = int.Parse(this.Request.Get("mediaType"));
                Dictionary <String, String> fileData = this.Request.GetValidatedFile(httpRequest, mediaType);

                AbstractMedia media = new AbstractMedia {
                    Id       = int.Parse(this.Request.Get("id")),
                    Name     = this.Request.Get("name"),
                    Album    = new AlbumRepository().FindById(int.Parse(this.Request.Get("album"))),
                    Gender   = new GenderRepository().FindById(int.Parse(this.Request.Get("gender"))),
                    Category = new CategoryRepository().FindById(int.Parse(this.Request.Get("category"))),
                    Status   = new StatusRepository().FindStatusByCode(this.Request.Get("status")),
                    Size     = fileData["fileSize"],
                    Source   = fileData["fileDestination"]
                };
                new MediaRepository().Edit(media);

                return(new Response(true, "Contenido editado exitosamente!").ToJson());
            } catch (NullReferenceException) {
                return(new Response(false, "No se han enviado todos los parametros necesarios para editar el contenido.").ToJson());
            } catch (Exception ex) {
                return(new Response(false, ex.Message).ToJson());
            }
        }
        public string Add([FromForm] string json)
        {
            try {
                this.Request = new Request(json);
                HttpRequest httpRequest = HttpContext.Request;
                int         mediaType   = int.Parse(this.Request.Get("mediaType"));
                Dictionary <String, String> fileData = this.Request.GetValidatedFile(httpRequest, mediaType);

                AbstractMedia media = new AbstractMedia {
                    Name     = this.Request.Get("name"),
                    Album    = new AlbumRepository().FindById(int.Parse(this.Request.Get("album"))),
                    Gender   = new GenderRepository().FindById(int.Parse(this.Request.Get("gender"))),
                    Category = new CategoryRepository().FindById(int.Parse(this.Request.Get("category"))),
                    Size     = fileData["fileSize"],
                    Source   = fileData["fileDestination"]
                };
                int Id = new MediaRepository().Add(media);

                switch (mediaType)
                {
                case 1:     // Musica
                    new MusicRepository().Add(new Music()
                    {
                        Id = Id
                    });
                    break;

                case 2:     // Video
                    new VideoRepository().Add(new Video()
                    {
                        Id = Id
                    });
                    break;

                case 3:     // Libro
                    new BookRepository().Add(new Book()
                    {
                        Id = Id
                    });
                    break;

                case 4:     // Imagen
                    new ImageRepository().Add(new Image()
                    {
                        Id = Id
                    });
                    break;
                }

                return(new Response(true, "Contenido creado exitosamente!").ToJson());
            } catch (NullReferenceException) {
                return(new Response(false, "No se han enviado todos los parametros necesarios para crear el contenido.").ToJson());
            } catch (Exception ex) {
                return(new Response(false, ex.Message).ToJson());
            }
        }
Beispiel #3
0
 public void Remove(AbstractMedia media)
 {
     try {
         String QueryTemplate = "UPDATE {0} SET Status = 'B' WHERE Id = {1}";
         String Query         = String.Format(QueryTemplate, this.Table, media.Id);
         this.ExecUpdate(Query);
     } catch (Exception ex) {
         throw ex;
     } finally {
         this.SqlConnection.Close();
     }
 }
Beispiel #4
0
 public void Edit(AbstractMedia media)
 {
     try {
         String QueryTemplate = "UPDATE {0} SET Album = {1}, Name = {2}, Gender = {3}, Category = {4}, Size = '{5}', Source = '{6}', Status = '{7}' WHERE Id = {8}";
         String Query         = String.Format(QueryTemplate, this.Table, media.Album.Id, media.Name, media.Gender.Id, media.Category.Id, media.Size, media.Source, media.Status.Code, media.Id);
         this.ExecUpdate(Query);
     } catch (Exception ex) {
         throw ex;
     } finally {
         this.SqlConnection.Close();
     }
 }
        public string Remove([FromForm] string json)
        {
            try {
                this.Request = new Request(json);
                AbstractMedia media = new AbstractMedia {
                    Id = int.Parse(this.Request.Get("id"))
                };
                new MediaRepository().Remove(media);

                return(new Response(true, "Album eliminado exitosamente!").ToJson());
            } catch (NullReferenceException) {
                return(new Response(false, "No se han enviado todos los parametros necesarios para eliminar al album.").ToJson());
            } catch (Exception ex) {
                return(new Response(false, ex.Message).ToJson());
            }
        }
Beispiel #6
0
        public int Add(AbstractMedia media)
        {
            try {
                String QueryTemplate = "INSERT INTO {0} (Album, Name, Gender, Category, Size, Source) VALUES ({1}, '{2}', {3}, {4}, '{5}', '{6}')";
                String Query         = String.Format(QueryTemplate, this.Table, media.Album.Id, media.Name, media.Gender.Id, media.Category.Id, media.Size, media.Source);
                this.ExecInsert(Query);
                this.SqlConnection.Close();
                Query = String.Format("SELECT MAX(Id) AS Id FROM {0}", this.Table);
                this.ExecSelect(Query);
                this.SqlDataReader.Read();

                return(DBTransformer.GetOrDefault(this.SqlDataReader["Id"], 0));
            } catch (Exception ex) {
                throw ex;
            } finally {
                this.SqlConnection.Close();
            }
        }