/// <summary> /// Add event to user´s calendar /// http://developer.teamwork.com/events#create_event /// </summary> /// <param name="data"></param> /// <returns></returns> public async Task <int> AddCalendarEntry(EventCreate data) { try { using (var client = new AuthorizedHttpClient(_client)) { var settings = new JsonSerializerSettings() { ContractResolver = new NullToEmptyStringResolver() }; string post = JsonConvert.SerializeObject(data, settings); var response = await client.PostWithReturnAsync("calendarevents.json", new StringContent("{\"event\":" + post + "}", Encoding.UTF8)); if (response.StatusCode == HttpStatusCode.OK) { var id = response.ContentObj; int returnval; if (int.TryParse(id.ToString(), out returnval)) { return(returnval); } } } return(-1); } catch (Exception) { return(-1); } }
public async Task <ActionResult <List <Event> > > createEvent([FromBody] EventCreate model, [FromServices] DataContext context) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var user = await context.Users.FirstOrDefaultAsync(x => x.Id == int.Parse(this.User.FindFirstValue(ClaimTypes.Sid))); Event newEvent = new Event(); newEvent.Name = model.Name; newEvent.Date = model.Date; newEvent.UserCreator = user; context.Events.Add(newEvent); await context.SaveChangesAsync(); return(Ok(newEvent)); } catch { return(BadRequest(new { message = "Não foi possivel criar o evento" })); } }
public ActionResult Create(EventCreate model) { Subject subject = _db.Subjects.Find(model.SubjectID); if (subject == null) { return(HttpNotFound("Subject not found")); } Location location = _db.Locations.Find(model.LocationID); if (location == null) { return(HttpNotFound("Location not found")); } if (!ModelState.IsValid) { return(View(model)); } var service = CreateEventService(); if (service.CreateEvent(model)) { TempData["SaveResult"] = "Your event has been created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Event could not be created."); return(View(model)); }
public async Task PostValidModelCallsServiceAndReturnsCreated(EventCreate createModel, int newId) { var service = new Mock <IEventService>(MockBehavior.Strict); var model = createModel.ToItem(); service.Setup(s => s.AddAsync(It.Is <Event>(m => model.Equals(m)))).ReturnsAsync(newId); var controller = GetController(service.Object); var helper = new Mock <IUrlHelper>(MockBehavior.Strict); controller.Url = helper.Object; var result = await controller.Post(createModel); result.Should().NotBeNull().And.BeOfType <CreatedAtActionResult>(); var res = (CreatedAtActionResult)result; res.ControllerName.Should().BeNullOrEmpty(); res.ActionName.Should().Be("Get"); res.RouteValues.Should().NotBeNull().And.Contain(new[] { new KeyValuePair <string, object>("id", newId) }); res.Value.Should().NotBeNull().And.BeOfType <IdResult>().Which.Id.Should().Be(newId); service.VerifyAll(); }
public bool CreateEvent(EventCreate model) { Result LocationData = GetLocationData(model.Address); var entity = new Events() { CreatorId = _creatorId, EventRange = new DateRange() { Start = DateTime.Parse(model.Start), End = DateTime.Parse(model.End) }, Type = model.Type, EventTitle = model.EventTitle, Address = model.Address, City = model.City, Zip = model.Zip, State = model.State, Latitude = LocationData.geometry.location.lat.ToString(), Longitude = LocationData.geometry.location.lng.ToString(), VolunteersNeeded = model.VolunteersNeeded, EventDescription = model.EventDescription, Created = DateTime.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Events.Add(entity); return(ctx.SaveChanges() == 1); } }
public string Create(EventCreate model) { var entity = new Event() { TypeOfEvent = $"{model.TypeOfEvent}", BusinessID = model.BusinessID, StartDay = model.StartDayToString, StartMonth = model.StartMonthToString, StartYear = "{ model.StartYear }", start = model.Start, end = model.Start, ThirdPartyWebsite = model.Url, color = model.Color, description = model.Description, }; using (var ctx = new ApplicationDbContext()) { try { ctx.Events.Add(entity); ctx.SaveChanges(); return("okay"); } catch { } return("Error"); } }
public IActionResult NewEvent() { EventCreate creatingEvent = new EventCreate(); creatingEvent.CurrentUser = dbContext.Users.FirstOrDefault(user => user.UserId == HttpContext.Session.GetInt32("Validator")); return(View("New", creatingEvent)); }
public ActionResult Create(int id, EventCreate model) { if (!ModelState.IsValid) { return(View(model)); } var eventService = CreateEventService(); var profileService = CreateProfileService(); string result = eventService.Create(model); if (result == "okay") { var newEvent = eventService.GetByBusinessIDAndStart(model.BusinessID, model.StartDayToString); var activityFeedItem = new ActivityFeedCreate(); activityFeedItem.Activity = TypeOfActivity.NewEvent; activityFeedItem.Content = $"{newEvent.title} on {model.StartMonth}/{model.StartDay}/{model.StartYear}"; activityFeedItem.BusinessID = model.BusinessID; activityFeedItem.ObjectID = newEvent.id; activityFeedItem.ObjectType = "Event"; profileService.CreateBusinessFeedItem(activityFeedItem); TempData["SaveResult"] = "Event was created."; return(RedirectToAction($"Details/{model.BusinessID}", "Business")); } ; ModelState.AddModelError("", "Event could not be created."); return(View(model)); }
public ActionResult CreateRecurring(int id) { var model = new EventCreate(); model.BusinessID = id; return(View(model)); }
public ActionResult Create(EventCreate model) { //if(selectedFoods != null) //{ // foreach (var food in selectedFoods) // { // var eventService = CreateEventService(); // var foodId = int.Parse(food); // model.FoodId = foodId; // eventService.CreateEvent(model); // } //} if (!ModelState.IsValid) { return(View(model)); } var service = CreateEventService(); if (service.CreateEvent(model)) { TempData["SaveResult"] = " Your Event was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Event could not be created."); return(View(model)); }
public override void OnActionExecuted(ActionExecutedContext context) { ///Console and file Logger used, the log for me is in the .Web project root directory. ///Everything is logged, not only the custom message here. ///The log gets lost in other logs search for "Administrator" var eventCreateModel = new EventCreate { End = DateTime.Parse(context.HttpContext.Request.Form["End"]), Start = DateTime.Parse(context.HttpContext.Request.Form["Start"]), Name = context.HttpContext.Request.Form["Name"], Place = context.HttpContext.Request.Form["Place"], PricePerTicket = decimal.Parse(context.HttpContext.Request.Form["PricePerTicket"]), TotalTickets = int.Parse(context.HttpContext.Request.Form["TotalTickets"]) }; if (!context.ModelState.IsValid) { logger.LogInformation($"Event \"{eventCreateModel.Name}\" was not created because of invalid data!"); return; } logger.LogInformation($"[{DateTime.UtcNow.ToEventuresFormat()}] " + $"Administrator {context.HttpContext.User.Identity.Name} create " + $"event {eventCreateModel.Name} ({eventCreateModel.Start.ToEventuresFormat()} /" + $" {eventCreateModel.End.ToEventuresFormat()})."); base.OnActionExecuted(context); }
// CREATE public ActionResult Create(int id) { var model = new EventCreate(); model.BusinessID = id; ModelState.Clear(); return(View(model)); }
public ActionResult <EventDetailMore> CreateEvent(EventCreate eventtDTO) { var eventt = this.mapper.Map <Event>(eventtDTO); eventt = this.subNineRepository.Create(eventt); return(this.mapper.Map <EventDetailMore>(eventt)); }
public async Task PostInvalidItemDoesNotCallServiceAndReturnsBadRequest(EventCreate createModel) { var controller = GetController(null); controller.ModelState.AddModelError("", "Model is invalid"); var result = await controller.Post(createModel); result.Should().NotBeNull().And.BeOfType <BadRequestObjectResult>(); }
public IActionResult Create(EventCreate model) { if (ModelState.IsValid) { eventsService.Create(model); return(Redirect("/")); } return(View(model)); }
public IHttpActionResult Post(EventCreate @event) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateEventService(); if (!service.CreateEvent(@event)) { return(InternalServerError()); } return(Ok()); }
public bool CreateEvent(EventCreate model) { using (var ctx = new ApplicationDbContext()) { var newEvent = new Event() { Note = model.Note, EventType = model.EventType, CreatedUtc = DateTimeOffset.Now, DogId = model.DogId }; ctx.Events.Add(newEvent); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(EventCreate model) { if (!ModelState.IsValid) { return(View(model)); } if (new EventService().CreateEvent(model)) { TempData["SaveResult"] = "Event created"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Error creating an Event"); return(View(model)); }
public void Create(EventCreate model) { var @event = new Event { End = model.End, Start = model.Start, Name = model.Name, Place = model.Place, PricePerTicket = model.PricePerTicket, TotalTickets = model.TotalTickets, }; context.Events.Add(@event); context.SaveChanges(); }
// CREATE public bool CreateEvent(EventCreate model) { var entity = new Event { EventId = model.EventId, Type = model.Type, Description = model.Description, EventDate = model.EventDate, BreweryId = model.BreweryId, Brewery = model.Brewery }; _context.Events.Add(entity); return(_context.SaveChanges() == 1); }
public async Task <IActionResult> Post([FromBody] EventCreate createModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var model = createModel.ToItem(); var id = await Service.AddAsync(model); return(CreatedAtAction("Get", new { id }, new IdResult { Id = id })); }
public ActionResult Create(EventCreate model) { if (!ModelState.IsValid) { return(View(model)); } if (EventService.CreateEvent(model)) { TempData["SaveResult"] = "Your event was created"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Event could not be created"); return(View(model)); }
public IHttpActionResult PostEvent(EventCreate @event) { try { string headerToken = ts.getTokenFromHeader(Request); User u = db.Users.Include("Token") .Where(us => us.Token.AccessToken == headerToken).FirstOrDefault(); Hall eventHall = db.Halls.Find(@event.Hall); Event newEvent = new Event(); newEvent.Owner = u; newEvent.Hall = eventHall; newEvent.Name = @event.Name; newEvent.Duration = @event.Duration; newEvent.Start = @event.Start; newEvent.TicketPrice = @event.TicketPrice; newEvent.About = @event.About; var results = new List <ValidationResult>(); var context = new ValidationContext(newEvent, serviceProvider: null, items: null); var isValid = Validator.TryValidateObject(newEvent, context, results); if (!isValid) { var modelState = new ModelStateDictionary(); foreach (var validationResult in results) { modelState.AddModelError(validationResult.MemberNames.ToArray()[0], validationResult.ErrorMessage); } return(BadRequest(modelState)); } db.Events.Add(newEvent); db.SaveChanges(); return(Ok(new EventPublic(newEvent))); } catch (Exception e) { return(InternalServerError(e)); } }
public bool CreateEvent(EventCreate model) { var entity = new Event() { OwnerId = _userId, EventName = model.EventName, EventType = model.EventType, Location = model.Location, EventDateTime = model.EventDateTime }; using (var ctx = new ApplicationDbContext()) { ctx.Events.Add(entity); return(ctx.SaveChanges() == 1); } }
// Create public bool CreateEvent(EventCreate model) { Event newEvent = new Event() { VenueId = model.VenueId, Date = model.Date, EventName = model.EventName, MaxTickets = model.MaxTickets, AvailableTickets = model.AvailableTickets, ExpectedRevenue = model.ExpectedRevenue }; using (ApplicationDbContext ctx = new ApplicationDbContext()) { ctx.Events.Add(newEvent); return(ctx.SaveChanges() == 1); } }
public bool CreateEvent(EventCreate model) { UserProfile userProfile = _db.UserProfiles.Single(up => up.OwnerId == _userId); Event thisEvent = new Event() { OwnerId = _userId, Title = model.Title, Description = model.Description, EventTime = DateTime.Now, IsOfAge = model.IsOfAge, ActivityId = model.ActivityId, LocationId = model.LocationId }; _db.Events.Add(thisEvent); return(_db.SaveChanges() == 1); }
public bool CreateEvent(EventCreate model) { var entity = new Event() { OwnerId = _userId, Title = model.Title, Overview = model.Overview, Location = model.Location, DateTime = model.DateTime }; using (var ctx = new ApplicationDbContext()) { ctx.Events.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(EventCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateEventService(); if (service.CreateEvent(model)) { TempData["SaveResult"] = "Event was successfully created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Event could not be created."); return(View(model)); }
public bool EventCreate(EventCreate model) { var entity = new Event() { OwnerId = _userId, EventStartTime = model.EventStartTime, EventEndTime = model.EventEndTime, EventName = model.EventName, EventTopic = model.EventTopic, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Events.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateEvent(EventCreate model) { var entity = new Event() { EventName = model.EventName, CreatorId = _creatorId, GroupId = model.GroupId, BookId = model.BookId, ScheduledDate = model.ScheduledDate }; using (var ctx = new ApplicationDbContext()) { ctx.Events.Add(entity); return(ctx.SaveChanges() == 1); } }