Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SetPageTitle("PhishMarket Profile Step 2");
            BasicJSONifier j = new BasicJSONifier("record", "ID", "Show");

            if (!IsPostBack)
            {
                BindLists();

                BindProfile();
            }
        }
        public override void ProcessRequest(HttpContextBase context)
        {
            HttpRequestBase  request  = context.Request;
            var              l        = request.QueryString["l"];
            var              r        = request.QueryString["r"];
            HttpResponseBase response = context.Response;

            Guid   listenedId;
            double rating;

            if (!(Guid.TryParse(l, out listenedId) && double.TryParse(r, out rating)))
            {
                return;
            }

            var success = false;

            try {
                var listenedService = Ioc.GetInstance <IListenedShowService>();

                using (IUnitOfWork uow = UnitOfWork.Begin()) {
                    var listenedShow = listenedService.GetById(listenedId);

                    //If there is no listened show then there is no way
                    // that a rating can be taking place. Notes creates a new
                    //  listened show for you if one does not already exist.
                    if (listenedShow == null)
                    {
                        return;
                    }

                    listenedShow.Stars       = rating;
                    listenedShow.UpdatedDate = DateTime.UtcNow;

                    uow.Commit();
                    success = true;
                }
            }
            catch (Exception ex) {
                writer.WriteFatal(" THERE WAS AN EXCEPTION SAVING THE RATING ON NOTES.ASPX" + ex.Message);
            }

            var jsonifier = new BasicJSONifier("records", "Question", "Answer");

            jsonifier.Add("success", success.ToString());
            var final = jsonifier.GetFinalizedJSON();

            response.ContentType     = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);
            response.End();
        }
        public override void ProcessRequest(HttpContextBase context)
        {
            HttpRequestBase  request   = context.Request;
            var              tourIdStr = request.QueryString["t"];
            HttpResponseBase response  = context.Response;

            string final;

            //string final = "{\"records\":[{\"Show\":\"Keep your current selection\",\"ID\":\"-1\"},{\"Show\":\"12/27/2010 - DCU Center - Worcester, MA\",\"ID\":\"cb62c626-dda0-46bc-b4d9-6eed30cbcdf8\"},{\"Show\":\"12/28/2010 - DCU Center - Worcester, MA\",\"ID\":\"e852d885-7e74-4aca-903c-81bd67d31129\"},{\"Show\":\"12/30/2010 - Madison Square Garden - New York, NY\",\"ID\":\"15ce4a44-9833-4901-acf8-43cec36e1f06\"},{\"Show\":\"12/31/2010 - Madison Square Garden - New York, NY\",\"ID\":\"88314a34-07d1-464b-8c70-a88628c71036\"},{\"Show\":\"01/01/2011 - Madison Square Garden - New York, NY\",\"ID\":\"dc586a9a-497e-4257-a3d5-d9e326e12bfb\"}]}";

            if (tourIdStr != "-1")
            {
                var tourId = new Guid(tourIdStr);

                ShowService showService = new ShowService(Ioc.GetInstance <IShowRepository>());
                var         shows       = showService.GetOfficialShows(tourId).ToList();


                if (shows != null && shows.Count > 0)
                {
                    var jsonifier = new BasicJSONifier("records", "ID", "Show", "-1", "Keep your current selection");

                    shows.ForEach(x =>
                    {
                        jsonifier.Add(x.ShowId.ToString(), x.GetShowName());
                    }
                                  );

                    final = jsonifier.GetFinalizedJSON();
                }
                else
                {
                    var jsonifier = new BasicJSONifier("records", "ID", "Show");
                    jsonifier.Add("-1", "There are no shows for this tour");
                    final = jsonifier.GetFinalizedJSON();
                }
            }
            else
            {
                var jsonifier = new BasicJSONifier("records", "ID", "Show");
                jsonifier.Add("-1", "Please choose a tour");
                final = jsonifier.GetFinalizedJSON();
            }

            response.ContentType     = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);
            //Response.End();
        }
        public override void ProcessRequest( HttpContextBase context )
        {
            HttpRequestBase request = context.Request;
            var l = request.QueryString["l"];
            var r = request.QueryString["r"];
            HttpResponseBase response = context.Response;

            Guid listenedId;
            double rating;

            if ( !( Guid.TryParse( l, out listenedId ) && double.TryParse( r, out rating ) ) ) return;

            var success = false;

            try {

                var listenedService = Ioc.GetInstance<IListenedShowService>();

                using ( IUnitOfWork uow = UnitOfWork.Begin() ) {
                    var listenedShow = listenedService.GetById( listenedId );

                    //If there is no listened show then there is no way
                    // that a rating can be taking place. Notes creates a new
                    //  listened show for you if one does not already exist.
                    if ( listenedShow == null ) return;

                    listenedShow.Stars = rating;
                    listenedShow.UpdatedDate = DateTime.UtcNow;

                    uow.Commit();
                    success = true;
                }

            }
            catch ( Exception ex ) {
                writer.WriteFatal( " THERE WAS AN EXCEPTION SAVING THE RATING ON NOTES.ASPX" + ex.Message );
            }

            var jsonifier = new BasicJSONifier( "records", "Question", "Answer" );
            jsonifier.Add( "success", success.ToString() );
            var final = jsonifier.GetFinalizedJSON();

            response.ContentType = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write( final );
            response.End();
        }
        public override void ProcessRequest(HttpContextBase context)
        {
            HttpRequestBase  request  = context.Request;
            var              sDate    = request.QueryString["s"];
            var              uId      = request.QueryString["u"];
            var              st       = request.QueryString["st"];
            HttpResponseBase response = context.Response;

            Guid     userId;
            DateTime showDate;
            int      status  = 0;
            bool     success = false;
            string   final;
            bool     displayAttended = false;
            int      displayStatus   = 0;

            //Get the show date, user id, and status from the request and parse them into concrete types
            if (!(DateTime.TryParse(sDate, out showDate) && Guid.TryParse(uId, out userId) && int.TryParse(st, out status)))
            {
                return;
            }

            var listenedShowService = Ioc.GetInstance <IListenedShowService>();;
            var showService         = new ShowService(Ioc.GetInstance <IShowRepository>());

            var show = showService.GetShow(showDate);

            //see if the user has an entry for this show yet
            var listenedShow = listenedShowService.GetByUserAndShowId(userId, show.Id);
            //Setup the JSON Builder
            var jsonifier = new BasicJSONifier("records", "Question", "Answer");

            //If status is EditNotes don't do anything and just get out of here
            if (status == (int)ListenedStatus.EditNotes)
            {
                return;
            }

            try {
                //If the user has one then update it
                if (listenedShow != null)
                {
                    //if ( status != (int)ListenedStatus.EditNotes ) {
                    using (IUnitOfWork uow = UnitOfWork.Begin()) {
                        if (status != (int)ListenedStatus.Attended)
                        {
                            var prevStatus = listenedShow.Status;

                            if (status == (int)ListenedStatus.EditNotes)
                            {
                                status = prevStatus;
                            }

                            listenedShow.Status      = status;
                            listenedShow.UpdatedDate = Constants.Now();

                            //For display purposes on Main.
                            displayAttended = listenedShow.Attended;
                            //This needs to be here because if edit notes is the status we need to make sure we take the previous status
                            displayStatus = status;

                            writer.Write(string.Format("Updating listenedShow with Id:{0}, from the status: {1}, to the status: {2}", listenedShow.Id, prevStatus, status));
                        }
                        else
                        {
                            //What it was before, make it the opposite
                            listenedShow.Attended    = !listenedShow.Attended;
                            listenedShow.UpdatedDate = Constants.Now();

                            //For display purposes on Main.
                            displayAttended = listenedShow.Attended;
                            //This needs to be here b/c we don't know what old status was otherwise
                            displayStatus = listenedShow.Status;

                            writer.Write("Updating listenedShow with Id:" + listenedShow.Id + "with Attended = " + !listenedShow.Attended);
                        }

                        uow.Commit();
                        success = true;
                        writer.Write("Successfully updated listenedShow id: " + listenedShow.Id);
                    }
                    //}
                }
                else
                {
                    //If the user does not have one then create it
                    var objectFactory = Ioc.GetInstance <IDomainObjectFactory>();

                    bool attended;
                    if (status == (int)ListenedStatus.Attended)
                    {
                        attended = true;
                    }
                    else
                    {
                        attended = false;
                    }

                    var newListenedShow = objectFactory.CreateListenedShow(show.Id, userId, show.ShowDate.Value, status, string.Empty, attended);
                    displayAttended = attended;
                    displayStatus   = status;

                    writer.Write(string.Format("Saving a new listenedShow with Id:{0} with a status of {1}, and attended is {2}", newListenedShow.Id, status, attended));

                    listenedShowService.SaveCommit(newListenedShow, out success);

                    if (success)
                    {
                        writer.Write("Successfully saved the new listenedShow with id: " + newListenedShow.Id);
                    }
                }
            }
            catch (Exception ex) {
                writer.WriteFatal("There was an error saving a listenedShow. The exception is: " + ex.Message);
                success = false;
            }

            if (success)
            {
                jsonifier.Add("success", "true");
                jsonifier.Add("attended", displayAttended.ToString());
                jsonifier.Add("status", displayStatus.ToString());
            }
            else
            {
                jsonifier.Add("success", "false");
            }

            final = jsonifier.GetFinalizedJSON();

            response.ContentType     = "application/json";
            response.ContentEncoding = Encoding.UTF8;
            response.Write(final);
            response.End();
        }