コード例 #1
0
ファイル: EventProcessorTest.cs プロジェクト: Dymus/gms
        public void TestUpdate()
        {
            Event event1             = new Event();
            bool  test1              = false;
            bool  test2              = true;
            bool  TestThrewException = false;

            try
            {
                ep.InsertEvent(testEvent.Name, testEvent.EventType, testEvent.Location,
                               testEvent.Date, testEvent.Description, testEvent.MaxNumberOfCharacters, testEvent.GuildID);
                int   id = ea.GetIdOfEvent(testEvent.Name);
                Event eventToBeUpdated = ep.GetEventByID(id);
                eventToBeUpdated.Location = "Update";
                test1 = ep.UpdateEvent(eventToBeUpdated.EventID, eventToBeUpdated.Name, eventToBeUpdated.EventType,
                                       eventToBeUpdated.Location, eventToBeUpdated.Date, eventToBeUpdated.Description,
                                       eventToBeUpdated.MaxNumberOfCharacters, eventToBeUpdated.GuildID, eventToBeUpdated.RowId);
                //Since the rowID wasnt updated this update should fail
                eventToBeUpdated.Location = "Another update";
                test2 = ep.UpdateEvent(eventToBeUpdated.EventID, eventToBeUpdated.Name, eventToBeUpdated.EventType,
                                       eventToBeUpdated.Location, eventToBeUpdated.Date, eventToBeUpdated.Description,
                                       eventToBeUpdated.MaxNumberOfCharacters, eventToBeUpdated.GuildID, eventToBeUpdated.RowId);
                event1 = ep.GetEventByID(id);
            }catch (Exception)
            {
                TestThrewException = true;
            }finally
            {
                //Cleanup
                int id = ea.GetIdOfEvent(testEvent.Name);
                ea.DeleteEventByID(id);
            }

            Assert.AreEqual("Update", event1.Location);
            Assert.IsTrue(test1);
            Assert.IsFalse(test2);
            Assert.IsFalse(TestThrewException);
        }
コード例 #2
0
ファイル: EventController.cs プロジェクト: Dymus/gms
 public ActionResult UpdateEventForm(string name, int eventID, bool error = false)
 {
     if (InSession())
     {
         this.Session["characterName"] = name;
         string urlSuffix = "gw2api/characters/" + name + "/core";
         ViewBag.Character = GetJson <Character>(urlSuffix);
         ViewBag.UserToken = Session["UserToken"];
         // Getting all event types needed for DropDownList
         var eventTypes = GetAllEventTypes();
         var model      = new EventModel();
         model.EventTypes = GetOptionEventTypesList(eventTypes);
         model.GuildID    = ViewBag.Character.Guild;
         // Get info about event
         EventProcessor processor = new EventProcessor();
         Event          events    = processor.GetEventByID(eventID);
         if (events is null)
         {
             TempData["ErrorMessage"] = "This Event no longer exists";
             return(RedirectToAction("SearchEvents", "Event", new { name = this.Session["characterName"] }));
         }
         else
         {
             Event eventToBeUpdated = events;
             model.eventID                    = eventToBeUpdated.EventID;
             model.EventName                  = eventToBeUpdated.Name;
             model.EventType                  = eventToBeUpdated.EventType;
             model.EventLocation              = eventToBeUpdated.Location;
             model.EventDateTime              = eventToBeUpdated.Date;
             model.EventDescription           = eventToBeUpdated.Description;
             model.EventMaxNumberOfCharacters = eventToBeUpdated.MaxNumberOfCharacters;
             model.rowID   = eventToBeUpdated.RowId;
             model.GuildID = eventToBeUpdated.GuildID;
             if (error)
             {
                 ViewBag.Error = "The record you attempted to edit was modified by another user after you got the original value. " +
                                 "The edit operation was cancelled and the current values in the database have been displayed. " +
                                 "If you still want to edit this record, click the Update button again. Otherwise click the Back to List hyperlink";
             }
             return(View(model));
         }
     }
     ViewBag.Error = "You aren't authorized to access this page.";
     return(RedirectToAction("Index", "Home"));
 }
コード例 #3
0
ファイル: GuildController.cs プロジェクト: Dymus/gms
        public ActionResult <Event> Get(string eventId)
        {
            IAuthService authService = new JWTService(clientSettings.Value.SecretKey);
            string       token       = HttpContext.Request.Headers["Authorization"];

            try
            {
                if (!authService.IsTokenValid(token))
                {
                    return(BadRequest("Unauthorized Access"));
                }
                else
                {
                    return(eventProcessor.GetEventByID(Int32.Parse(eventId)));
                }
            } catch
            {
                return(BadRequest("Unauthorized Access"));
            }
        }