Example #1
0
        public string addMovie(AddMovieRequestJSON req)
        {
            string res = string.Empty;

            using (MovieEntities db = new MovieEntities())
            {
                foreach (var item in req.Movies)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var actor in item.actors)
                    {
                        sb.Append(actor + ",");
                    }
                    DateTime dt = DateTime.Now;
                    DateTime.TryParse(item.releasedate, out dt);

                    ObjectParameter output_result = new ObjectParameter("Result", typeof(Int32));
                    string          title         = !string.IsNullOrWhiteSpace(item.title) ? item.title : null;
                    string          description   = !string.IsNullOrWhiteSpace(item.description) ? item.description : null;
                    string          language      = !string.IsNullOrWhiteSpace(item.language) ? item.language : null;
                    string          genre         = !string.IsNullOrWhiteSpace(item.genre) ? item.genre : null;
                    string          actors        = !string.IsNullOrWhiteSpace(sb.ToString().TrimEnd(',')) ? sb.ToString().TrimEnd(',') : null;
                    decimal         finalprice    = 0.0m;
                    if (item.price.HasValue)
                    {
                        finalprice = item.price.Value;
                    }
                    db.pr_AddMovies(title, description, genre, language, dt, actors, finalprice, output_result);
                    if (output_result.Value != null)
                    {
                        int ouserId = (int)output_result.Value;
                        if (ouserId == 0)
                        {
                            res = "ERR:There seems to be an issue while adding Movies. Please try again.";
                            return(res);
                        }
                    }
                }
            }
            return("Movies Added Successfully");
        }
Example #2
0
        public HttpResponseMessage addMovies(AddMovieRequestJSON ureq)
        {
            req = Request;
            if (ureq == null)
            {
                return(Utils.CreateEmptyErrorResponse(req));
            }

            if (!movie.isAdmin(ureq.userId))
            {
                return(Utils.CreateErrorResponse(req, "Only an admin is allowed to do this operation"));
            }

            string res = movie.addMovie(ureq);

            if (res.Contains("ERR"))
            {
                return(Utils.CreateErrorResponse(req, res));
            }

            return(Utils.CreateSuccessResponse(req, res));
        }