Example #1
0
        public string rentMovies(RentMoviesRequestJSON res)
        {
            string status = "";

            try
            {
                using (MovieEntities db = new MovieEntities())
                {
                    foreach (var item in res.moviesIds)
                    {
                        UsersRental ur = new UsersRental();
                        ur.Users_ID  = res.userId;
                        ur.Movies_ID = item;
                        DateTime datefrom = convertToDate(res.RentalDateFrom);
                        DateTime dateto   = convertToDate(res.RentalDateTo);
                        if (datefrom == DateTime.Now)
                        {
                            ur.RentalDateFrom = null;
                        }
                        else
                        {
                            ur.RentalDateFrom = datefrom;
                        }
                        if (dateto == DateTime.Now)
                        {
                            ur.RentalDateTo = null;
                        }
                        else
                        {
                            ur.RentalDateTo = dateto;
                        }
                        ur.UsersTransaction_ID = null;
                        ur.CreatedDate         = DateTime.UtcNow;
                        db.UsersRentals.Add(ur);
                        db.SaveChanges();
                    }

                    /* if authorizePayment is set to true user credit card details can obtained from Users table.
                     * if true, we can get these details from Users table and charge accordingly using Stripe or Authorize.net library
                     */
                    status = "Rented successfully";
                }
            }
            catch
            {
                status = "ERR: There seems to be issue with rental. Please try again.";
            }

            return(status);
        }
Example #2
0
        public HttpResponseMessage rentMovies(RentMoviesRequestJSON ureq)
        {
            req = Request;
            if (ureq == null)
            {
                return(Utils.CreateEmptyErrorResponse(req));
            }
            if (string.IsNullOrWhiteSpace(ureq.userId.ToString()))
            {
                return(Utils.CreateErrorResponse(req, "userId is required"));
            }
            if (ureq.moviesIds.Count() == 0)
            {
                return(Utils.CreateErrorResponse(req, "At least one moveid(s) is required."));
            }

            if (string.IsNullOrWhiteSpace(ureq.RentalDateFrom))
            {
                return(Utils.CreateErrorResponse(req, "RentalDateFrom is required"));
            }

            if (string.IsNullOrWhiteSpace(ureq.RentalDateTo))
            {
                return(Utils.CreateErrorResponse(req, "RentalDateTo is required"));
            }

            if (!Utils.checkDate(ureq.RentalDateFrom))
            {
                return(Utils.CreateErrorResponse(req, "RentalDateFrom is not a valid datetime."));
            }

            if (!Utils.checkDate(ureq.RentalDateTo))
            {
                return(Utils.CreateErrorResponse(req, "RentalDateTo is not a valid datetime."));
            }
            return(Utils.CreateSuccessResponse(req, users.rentMovies(ureq)));
        }