public IHttpActionResult Post(User user)
        {
            try
            {
                using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
                {
                    User existing = dbcontext.Users.FirstOrDefault(u => u.name == user.name);
                    if (existing != null)
                    {
                        return(BadRequest("Username exist, please select another username."));
                    }
                    existing = dbcontext.Users.FirstOrDefault(u => u.emailid == user.emailid);
                    if (existing != null)
                    {
                        return(BadRequest("Emailid exist, please select another emailid."));
                    }

                    dbcontext.Users.Add(user);
                    dbcontext.SaveChanges();
                    return(Ok(user));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Error : " + ex));
            }
        }
        public IHttpActionResult Post()
        {
            var request = HttpContext.Current.Request;

            try
            {
                if (request.Files.Count == 2)
                {
                    //imagefile
                    var imageurl     = request.Files["imageurl"];
                    var uploadFolder = HttpContext.Current.Server.MapPath("~/uploads");

                    String uniqueImageFileName = (Guid.NewGuid().ToString() + imageurl.FileName);
                    String imagefilePath       = uploadFolder + "/" + uniqueImageFileName;
                    imageurl.SaveAs(imagefilePath);

                    //video file
                    var videourl = request.Files["videourl"];

                    String uniquevideoFileName = (Guid.NewGuid().ToString() + videourl.FileName);
                    String videofilePath       = uploadFolder + "/" + uniquevideoFileName;
                    videourl.SaveAs(videofilePath);

                    using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
                    {
                        Movie movie = new Movie();
                        movie.name       = request["name"];
                        movie.language   = request["language"];
                        movie.categories = request["categories"];
                        //movie.duration = request["duration"];
                        movie.releaseddate = request["releaseddate"];
                        movie.story        = request["story"];
                        movie.forkid       = request["forkid"] == "1";
                        movie.views        = 0;
                        movie.imageurl     = "/uploads/" + uniqueImageFileName;
                        movie.videourl     = "/uploads/" + uniquevideoFileName;

                        dbcontext.Movies.Add(movie);
                        dbcontext.SaveChanges();
                        return(Ok(movie));
                    }
                }
                else
                {
                    return(BadRequest("Please upload both image and video files"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Error : " + ex));
            }
        }
Ejemplo n.º 3
0
        public IHttpActionResult Post()
        {
            var request = HttpContext.Current.Request;

            try
            {
                if (request.Files.Count == 2)
                {
                    //imagefile
                    var imageurl     = request.Files["imageurl"];
                    var uploadFolder = HttpContext.Current.Server.MapPath("~/uploads");

                    String uniqueImageFileName = (Guid.NewGuid().ToString() + imageurl.FileName);
                    String imagefilePath       = uploadFolder + "/" + uniqueImageFileName;
                    imageurl.SaveAs(imagefilePath);

                    //video file
                    var videourl = request.Files["videourl"];

                    String uniquevideoFileName = (Guid.NewGuid().ToString() + videourl.FileName);
                    String videofilePath       = uploadFolder + "/" + uniquevideoFileName;
                    videourl.SaveAs(videofilePath);

                    using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
                    {
                        Episode episode = new Episode();
                        episode.name     = request["name"];
                        episode.seriesid = Convert.ToInt32(request["seriesid"]);
                        episode.date     = System.DateTime.Now.ToShortDateString();
                        episode.views    = 0;
                        episode.likes    = 0;
                        episode.dislikes = 0;
                        episode.imageurl = "/uploads/" + uniqueImageFileName;
                        episode.videourl = "/uploads/" + uniquevideoFileName;

                        dbcontext.Episodes.Add(episode);
                        dbcontext.SaveChanges();
                        return(Ok(episode));
                    }
                }
                else
                {
                    return(BadRequest("Please upload both image and video files"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest("Error : " + ex));
            }
        }
 public IHttpActionResult Post(Category category)
 {
     try
     {
         using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
         {
             dbcontext.Categories.Add(category);
             dbcontext.SaveChanges();
             return(Ok(category));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error : " + ex));
     }
 }
Ejemplo n.º 5
0
 public IHttpActionResult Post(Language language)
 {
     try
     {
         using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
         {
             dbcontext.Languages.Add(language);
             dbcontext.SaveChanges();
             return(Ok(language));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error : " + ex));
     }
 }
Ejemplo n.º 6
0
 public IHttpActionResult IncrViews(int id)
 {
     try
     {
         using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
         {
             Episode existing = dbcontext.Episodes.FirstOrDefault(e => e.id == id);
             if (existing == null)
             {
                 return(NotFound());
             }
             else
             {
                 existing.views = existing.views + 1;
                 dbcontext.SaveChanges();
                 return(Ok(existing.views));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error : " + ex));
     }
 }
 public IHttpActionResult Delete(int id)
 {
     try
     {
         using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
         {
             Category existing = dbcontext.Categories.FirstOrDefault(c => c.id == id);
             if (existing == null)
             {
                 return(NotFound());
             }
             else
             {
                 dbcontext.Categories.Remove(existing);
                 dbcontext.SaveChanges();
                 return(Ok(existing));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error : " + ex));
     }
 }
Ejemplo n.º 8
0
 public IHttpActionResult Put(int id, Language language)
 {
     try
     {
         using (WebSeriesDBEntities dbcontext = new WebSeriesDBEntities())
         {
             Language existing = dbcontext.Languages.FirstOrDefault(l => l.id == id);
             if (existing == null)
             {
                 return(NotFound());
             }
             else
             {
                 existing.name = language.name;
                 dbcontext.SaveChanges();
                 return(Ok(existing));
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error : " + ex));
     }
 }