public async Task <IActionResult> Create(EventInputModel eventModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } decimal price = 0; if (!string.IsNullOrWhiteSpace(eventModel.Price) && !decimal.TryParse(eventModel.Price, NumberStyles.Currency, CultureInfo.InvariantCulture, out price)) { return(View()); } EventDto eventDto = MapModel(eventModel); eventDto.Price = price; if (eventModel.Image != null) { eventDto.ImageFileName = await SaveUploadedImage(eventModel.Image); } await _creationService.CreateEventAsync(eventDto); return(RedirectToAction(nameof(Index))); }
public ActionResult Create(EventInputModel model) { if (model != null && this.ModelState.IsValid) { //creating a temp event type of object which will be passed to database to be added var tempEvent = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, DateAndTime = model.Date, Duration = model.Duration, Description = model.Description, OtherDetails = model.OtherDetails, Location = model.Location, IsPublic = model.IsPublic, InviteList = model.InviteList }; if (tempEvent.InviteList == null) { this.dataBase.Events.Add(tempEvent); this.dataBase.SaveChanges(); TempData["SuccessMessage"] = "Event Created Succesfuly"; return(this.RedirectToAction("MyEvents")); } else { AddIntoInvites(tempEvent, true); TempData["SuccessMessage"] = "Event Created Succesfuly"; return(this.RedirectToAction("MyEvents")); } } return(this.View(model)); }
public ActionResult Create(EventInputModel model) { if (!this.ModelState.IsValid) { this.View(model); } var restaurantId = this.User.Identity.GetUserId(); DateTime baseDate = DateTime.UtcNow; var thisWeekStart = baseDate.AddDays(-(int)baseDate.DayOfWeek); var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1); var restaurant = this.restaurants.GetById(restaurantId); var dbevent = new Event { Name = model.Name, Description = model.Description, RestaurantId = restaurantId, ExpirationDate = thisWeekEnd, Participants = restaurant.RegularUsers }; this.events.Create(dbevent); return this.RedirectToAction("ListEvents", "ListEvents"); }
public ActionResult Create(EventInputModel model) { if (model != null && this.ModelState.IsValid) { string dbPath = null; if (Request.Files.Count > 0) { var file = Request.Files[0]; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extention = Path.GetExtension(file.FileName); fileName = "event-" + fileName + extention; dbPath = "/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); file.SaveAs(fileName); } var e = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, StartDateTime = model.StartDateTime, Duration = model.Duration, Description = model.Description, Location = model.Location, IsPublic = model.IsPublic, Path = dbPath, }; this.db.Events.Add(e); this.db.SaveChanges(); this.AddNotification("Event Created", NotificationType.INFO); return(this.RedirectToAction("My")); } return(this.View(model)); }
public ActionResult Edit(int Id, EventInputModel m) { Event e = LoadEvent(Id); if (e == null) { this.AddNotification("Cannot edit event # " + Id, NotificationType.ERROR); return(RedirectToAction("My")); } if (m != null && ModelState.IsValid) { e.Description = m.Description; e.Duration = m.Duration; e.IsPublic = m.IsPublic; e.Location = m.Location; e.StartDateTime = m.StartDateTime; e.Title = m.Title; db.SaveChanges(); this.AddNotification("Event edited successfully", NotificationType.INFO); return(RedirectToAction("My")); } return(View(m)); }
public async Task <bool> Add(EventInputModel eventInputModel) { List <EventPhoto> eventPhotos = new List <EventPhoto>(); if (eventInputModel.Photos != null) { foreach (var i in eventInputModel.Photos) { eventPhotos.Add(new EventPhoto(new Photo(i))); } } List <EventParticipants> eventParticipants = new List <EventParticipants>(); eventParticipants.Add(new EventParticipants(eventInputModel.personIdCadastro, true)); var eventId = await _eventRepository.Add(new Event(eventInputModel.Name, eventInputModel.StartDate, eventInputModel.EndDate, eventInputModel.PageProfileLink, eventInputModel.About, eventPhotos, eventParticipants)); await _addressRepository.Add(new Address(eventInputModel.Address.Longitude, eventInputModel.Address.Latitude, eventInputModel.Address.Street, eventInputModel.Address.Neighborhood, eventInputModel.Address.Province, eventInputModel.Address.Zip, eventInputModel.Address.City, eventInputModel.Address.Country, eventInputModel.Address.Number, personId : null, eventId : eventId)); return(eventId > 0); }
public ActionResult Edit(int id, EventInputModel model) { string currentUserId = this.User.Identity.GetUserId(); var isAdmin = this.IsAdmin(); // Loading of event which has permissions for admin and current Logged In user var eventToEdit = eventService.LoadEditEventDto(id, currentUserId, isAdmin); if (eventToEdit == null) { this.AddNotification("Cannot edit event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } if (model != null && this.ModelState.IsValid) { eventToEdit.Title = model.Title; eventToEdit.StartDateTime = model.StartDateTime; eventToEdit.Duration = model.Duration; eventToEdit.Description = model.Description; eventToEdit.Location = model.Location; eventToEdit.IsPublic = model.IsPublic; eventService.SaveChanges(); // Adding Notification To Event Editing Completed this.AddNotification("Event edited.", NotificationType.INFO); return(this.RedirectToAction("My")); } return(this.View(model)); }
public HttpResponseMessage POSTEventAttendees(EventInputModel model) { int affectedRows = 0; try { using (SqlConnection conn = new SqlConnection(con)) { SqlCommand sqlComm = new SqlCommand("Usp_InsertEventAttendees", conn); sqlComm.Parameters.AddWithValue("@Name", model.Name); sqlComm.Parameters.AddWithValue("@Email", model.Email); sqlComm.Parameters.AddWithValue("@Mobile", model.Mobile); sqlComm.Parameters.AddWithValue("@NoOfSeats", model.Seats); sqlComm.Parameters.AddWithValue("@AmountPaid", model.AmountPaid); sqlComm.Parameters.AddWithValue("@EventId", model.Id); sqlComm.CommandType = CommandType.StoredProcedure; conn.Open(); affectedRows = (int)sqlComm.ExecuteNonQuery(); conn.Close(); } } catch (Exception ex) { } return(Request.CreateResponse(HttpStatusCode.OK, affectedRows)); }
public ActionResult Edit(int id, EventInputModel model) { var eventToEdit = this.LoadEvent(id); if (eventToEdit == null) { this.AddNotification("Cannot edit event #" + id, NotificationType.ERROR); return this.RedirectToAction("My"); } if (model != null && this.ModelState.IsValid) { eventToEdit.Title = model.Title; eventToEdit.StartDateTime = model.StartDateTime; eventToEdit.Duration = model.Duration; eventToEdit.Description = model.Description; eventToEdit.Location = model.Location; eventToEdit.IsPublic = model.IsPublic; this.db.SaveChanges(); this.AddNotification("Event edited.", NotificationType.INFO); return this.RedirectToAction("My"); } return this.View(model); }
public HttpResponseMessage POSTCreateEvent(EventInputModel model) { int affectedRows = 0; //if () try { using (SqlConnection conn = new SqlConnection(con)) { SqlCommand sqlComm = new SqlCommand("Usp_CreateEvent", conn); sqlComm.Parameters.AddWithValue("@Title", model.Title); sqlComm.Parameters.AddWithValue("@StartDateTime", model.StartDateTime); sqlComm.Parameters.AddWithValue("@Duration", model.Duration); sqlComm.Parameters.AddWithValue("@Description", model.Description); sqlComm.Parameters.AddWithValue("@Location", model.Location); sqlComm.Parameters.AddWithValue("@IsPublic", model.IsPublic); sqlComm.Parameters.AddWithValue("@UserId", model.UserId); sqlComm.CommandType = CommandType.StoredProcedure; conn.Open(); affectedRows = (int)sqlComm.ExecuteNonQuery(); conn.Close(); } } catch (Exception ex) { } return(Request.CreateResponse(HttpStatusCode.OK, affectedRows)); }
public IActionResult Create(EventInputModel input, bool saveDraft = false) { if (!ModelState.IsValid) { return(View(input)); } var evnt = _mapper.Map <Event>(input); if (input.ProgramIds != null) { evnt.EventPrograms = input.ProgramIds.Select(id => new EventProgram { ProgramId = id, Event = evnt }).ToList(); } evnt.CreatorId = User.FindFirstValue(ClaimTypes.NameIdentifier); _eventService.AddEvent(evnt); _eventService.SaveChanges(); _logger.LogInformation("{user} created event {event}", User.Identity.Name, evnt.Id); return(saveDraft ? RedirectToAction("Index") : RedirectToAction("AdditionalInfo", new { id = evnt.Id })); }
// GET: Events/Create // [HttpPost] // [ValidateAntiForgeryToken] public ActionResult Create(EventInputModel model) { if (model != null && this.ModelState.IsValid) { var e = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, StartDateTime = model.StartDateTime, Duration = model.Duration, Description = model.Description, Location = model.Location, IsPublic = model.IsPublic }; this.db.Events.Add(e); this.db.SaveChanges(); // Display notification message "Event created." this.AddNotification("Event created.", NotificationType.INFO); return(this.RedirectToAction("My")); } return(this.View(model)); }
public ActionResult UpdateEvent(EventInputModel inputModel) { var model = new EventDTO { Id = inputModel.Id, EventName = inputModel.EventName, OddsForFirstTeam = inputModel.OddsForFirstTeam, OddsForDraw = inputModel.OddsForDraw, OddsForSecondTeam = inputModel.OddsForSecondTeam, EventStartDate = inputModel.EventStartDate, IsDeleted = inputModel.IsDeleted }; try { this.eventService.UpdateEvent(model); } catch (Exception ex) { return(Json(new { status = "error", message = "Error occured" })); } return(Json(new { status = "success", message = "Done" })); }
public ActionResult Edit(int id, EventInputModel model) { var eventToEdit = this.LoadEvent(id); if (eventToEdit == null) { this.AddNotification("Cannot edit event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } if (model != null && this.ModelState.IsValid) { eventToEdit.Title = model.Title; eventToEdit.StartDateTime = model.StartDateTime; eventToEdit.Duration = model.Duration; eventToEdit.Description = model.Description; eventToEdit.OtherDetails = model.OtherDetails; eventToEdit.Location = model.Location; eventToEdit.IsPublic = model.IsPublic; this.db.SaveChanges(); this.AddNotification("Event edited.", NotificationType.INFO); return(this.RedirectToAction("My")); } return(this.View(model)); }
public ActionResult Create(EventInputModel model) { if (model != null && this.ModelState.IsValid) { var e = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, StartDateTime = model.StartDateTime, Description = model.Description, Location = model.Location, IsPublic = model.IsPublic }; string role = roleCheck(); ViewBag.userRole = role; this.db.Events.Add(e); this.db.SaveChanges(); this.AddNotification("Event created", NotificationType.INFO); // Display success notification return this.RedirectToAction("My"); } return this.View(model); }
public ActionResult Edit(int id, EventInputModel model) { Event eventToEdit = LoadEvent(id); if (eventToEdit == null) { return(RedirectToAction("MyEvents")); } if (model != null && ModelState.IsValid) { eventToEdit.Title = model.Title; eventToEdit.DateAndTime = model.Date; eventToEdit.Duration = model.Duration; eventToEdit.Description = model.Description; eventToEdit.OtherDetails = model.OtherDetails; eventToEdit.Location = model.Location; eventToEdit.IsPublic = model.IsPublic; eventToEdit.InviteList = model.InviteList; dataBase.Database.Log = Console.Write; dataBase.SaveChanges(); UpdateInvites(eventToEdit); TempData["SuccessMessage"] = "Event Succesfully Edited"; return(this.RedirectToAction("MyEvents")); } return(this.View(model)); }
public IActionResult CreateEvent([FromBody] EventInputModel eventInputModel) { var newEvent = new Event(eventInputModel.Title, eventInputModel.Description, eventInputModel.TakesPlaceOn); _events.InsertOne(newEvent); return(CreatedAtAction(nameof(GetEventById), new { id = newEvent.Id.ToString() }, newEvent)); }
public ActionResult Create() { //The following code sets the default value of date to today's date which can be changed later by the user EventInputModel model = new EventInputModel(); //model.Date = DateTime.Now; return(View(model)); }
public ActionResult Delete(int id, EventInputModel model) { var eventToDelete = this.LoadEvent(id); this.db.Events.Remove(eventToDelete); this.db.SaveChanges(); this.AddNotification("Event deleted.", NotificationType.SUCCESS); return(this.RedirectToAction("My")); }
public async Task <bool> Update(EventInputModel eventInputModel) { List <EventPhoto> eventPhotos = new List <EventPhoto>(); if (eventInputModel.Photos != null) { foreach (var i in eventInputModel.Photos) { eventPhotos.Add(new EventPhoto(new Photo(i))); } } var @event = await _eventRepository.Get(eventInputModel.Id); @event.Update(eventInputModel.Name, eventInputModel.StartDate, eventInputModel.EndDate, eventInputModel.PageProfileLink, eventInputModel.About); @event.EventPhotos = eventPhotos; var eventId = await _eventRepository.Update(@event); var address = await _addressRepository.GetByEventId(eventId); if (address != null) { address.Update(eventInputModel.Address.Longitude, eventInputModel.Address.Latitude, eventInputModel.Address.Street, eventInputModel.Address.Neighborhood, eventInputModel.Address.Province, eventInputModel.Address.Zip, eventInputModel.Address.City, eventInputModel.Address.Country, eventInputModel.Address.Number, eventId: eventId, personId: null); await _addressRepository.Update(address); } else { await _addressRepository.Add(new Address(eventInputModel.Address.Longitude, eventInputModel.Address.Latitude, eventInputModel.Address.Street, eventInputModel.Address.Neighborhood, eventInputModel.Address.Province, eventInputModel.Address.Zip, eventInputModel.Address.City, eventInputModel.Address.Country, eventInputModel.Address.Number, personId : null, eventId : eventId)); } return(eventId > 0); }
public IActionResult Create(EventInputModel model) { if (!ModelState.IsValid) { return(this.View(model)); } this.EventService.CreateEvent(model); this.Logger.LogInformation($"Event created: {model.Name}, {model}"); return(RedirectToAction(nameof(All))); }
public ActionResult Edit(int id) { var eventToEdit = this.LoadEvent(id); if (eventToEdit == null) { this.AddNotification("cannot edit event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } var model = EventInputModel.CreateFromEvent(eventToEdit); return(this.View(model)); }
public ActionResult Delete(int id) { var eventToDelete = this.LoadEvent(id); if (eventToDelete == null) { this.AddNotification("Cannot delete the event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } var model = EventInputModel.CreateFromEvent(eventToDelete); return(View(model)); }
public async Task <bool> EventExists(EventInputModel model) { var ev = await _dbContext.Events.Include(e => e.Category) .Where(x => x.UserCreatedById == GetCurrentUsersId() && x.Title == model.Title && x.Category.Name == model.Category || x.Category.Name == model.SubCategory) .ToListAsync(); bool isDuplicate = ev.Any(x => Math.Abs((model.EventStartDate - x.EventStartDate).TotalHours) < 1); return(isDuplicate); }
public ActionResult Delete(int id) { Event eventToDelete = LoadEvent(id); if (eventToDelete == null) { return(this.RedirectToAction("MyEvents")); } var model = EventInputModel.CreateFromEvent(eventToDelete); return(View(model)); }
public ActionResult Events_Update([DataSourceRequest]DataSourceRequest request, EventInputModel eventUpdate) { if (this.ModelState.IsValid) { var entity = this.events.GetAll().FirstOrDefault(x => x.Id == eventUpdate.Id); entity.Name = eventUpdate.Name; entity.Description = eventUpdate.Description; entity.StartDate = eventUpdate.StartDate; this.events.Update(entity); } return this.Json(new[] { eventUpdate }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult Delete(int id, EventInputModel model) { var eventToDelete = this.LoadEvent(id); if (eventToDelete == null) { this.AddNotification("Cannot delete event #" + id, NotificationType.ERROR); return this.RedirectToAction("My"); } this.eventsdb.Events.Remove(eventToDelete); this.eventsdb.SaveChanges(); this.AddNotification("Event deleted.", NotificationType.INFO); return this.RedirectToAction("My"); }
public ActionResult Edit(int id) { Event eventToEdit = LoadEvent(id); if (eventToEdit == null || eventToEdit.DateAndTime < DateTime.Today) { TempData["Fail"] = "Passed event cannot be edited"; return(RedirectToAction("MyEvents")); } var model = EventInputModel.CreateFromEvent(eventToEdit); return(View(model)); }
public ActionResult Delete(int id, EventInputModel model) { var eventToDelete = this.LoadEvent(id); if (eventToDelete == null) { this.AddNotification("Cannot delete the event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } this.db.Events.Remove(eventToDelete); this.db.SaveChanges(); this.AddNotification("Event deleted", NotificationType.INFO); return(this.RedirectToAction("My")); }
public ActionResult Delete(int id, EventInputModel model) { Event eventToDelete = LoadEvent(id); if (eventToDelete == null) { return(this.RedirectToAction("MyEvents")); } this.dataBase.Database.Log = Console.Write; this.dataBase.Events.Remove(eventToDelete); this.dataBase.SaveChanges(); TempData["SuccessMessage"] = "Event Deleted Succesfuly"; return(this.RedirectToAction("MyEvents")); }
public ActionResult Delete(int id, EventInputModel events) { var currentUserId = this.User.Identity.GetUserId(); var eventToDelete = db.Events.Where(x => x.Id == id && x.AuthorId == currentUserId).FirstOrDefault(); if (eventToDelete != null) { db.Events.Remove(eventToDelete); db.SaveChanges(); this.AddNotification("Delete Success!", NotificationType.SUCCESS); return(RedirectToAction("MyEvents")); } this.AddNotification("You cannot delete an event created by someone", NotificationType.ERROR); return(RedirectToAction("Index", "Home")); }
public ActionResult Delete(int id) { var eventToEdit = this.LoadEvent(id); if (eventToEdit == null) { this.AddNotification("Cannot edit #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } ViewBag.EditCreate = "Delete"; var model = EventInputModel.CreateFromEvent(eventToEdit); return(View(model)); }
public ActionResult AddEvent(EventInputModel inputModel) { var model = new EventDTO { EventName = inputModel.EventName, OddsForFirstTeam = inputModel.OddsForFirstTeam, OddsForDraw = inputModel.OddsForDraw, OddsForSecondTeam = inputModel.OddsForSecondTeam, EventStartDate = inputModel.EventStartDate }; this.eventService.AddEvent(model); return(this.RedirectToAction(Views.IndexView)); }
public void CreateEvent(EventInputModel model) { var eventureEvent = new Event { Name = model.Name, PricePerTicket = model.PricePerTicket, TotalTickets = model.TotalTickets, End = model.End, Start = model.End, Place = model.Place }; this.Context.Events.Add(eventureEvent); this.Context.SaveChanges(); }
public ActionResult Delete(int id, EventInputModel model) { string currentUserId = this.User.Identity.GetUserId(); var isAdmin = this.IsAdmin(); var eventToDelete = eventService.LoadEditEventDto(id, currentUserId, isAdmin); if (eventToDelete == null) { this.AddNotification("Cannot delete event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } eventService.RemoveEventDto(eventToDelete); this.AddNotification("Event deleted.", NotificationType.INFO); return(this.RedirectToAction("My")); }
public ActionResult Create(EventInputModel model) { if (model != null && this.ModelState.IsValid) { var e = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, StartDateTime = model.StartDateTime, Duration = model.Duration, Description = model.Description, Location = model.Location, IsPublic = model.IsPublic }; this.eventsdb.Events.Add(e); this.eventsdb.SaveChanges(); this.AddNotification("Event created.", NotificationType.INFO); return this.RedirectToAction("My"); } return this.View(model); }
public ActionResult Create(EventInputModel model) { string lat = string.Empty; string lon = string.Empty; EventfulSearch coorResolver = new EventfulSearch(); string[] coord = resolveCoordinates(model.Address, model.City, model.State, model.Zip); int zip = 0; int.TryParse(model.Zip, out zip); if (coord != null && coord.Length == 2) { lat = coord[0]; lon = coord[1]; } if (model != null && this.ModelState.IsValid) { var e = new Event() { AuthorId = this.User.Identity.GetUserId(), Title = model.Title, StartDateTime = model.StartDateTime, Duration = model.Duration, Description = model.Description, Address = model.Address, City = model.City, Lat = lat, Lon = lon, State = model.State, Zip = zip > 9999 ? new Nullable<int>(zip) : null, IsPublic = model.IsPublic }; this.eventsdb.Events.Add(e); this.eventsdb.SaveChanges(); List<string> invitedUsers = new List<string>(); if(Request["Friends"]!= null) { invitedUsers = Request["Friends"].Split(',').ToList(); } foreach(string invitedUser in invitedUsers) { var invite = new EventInvite(); invite.FromUser = this.User.Identity.GetUserId(); invite.ToUser = invitedUser; invite.EventId = e.Id; eventsdb.EventInvites.Add(invite); } eventsdb.SaveChanges(); if (Request.Files != null && Request.Files.Count > 0) { SaveImages(e.Id); } this.AddNotification("Event created.", NotificationType.INFO); return this.RedirectToAction("My"); } return this.View(model); }
public ActionResult Edit(int id, EventInputModel model) { var eventToEdit = this.LoadEvent(id); if (eventToEdit == null) { this.AddNotification("Cannot edit event #" + id, NotificationType.ERROR); return this.RedirectToAction("My"); } int zip = 0; int.TryParse(model.Zip, out zip); if (model != null && this.ModelState.IsValid) { eventToEdit.Title = model.Title; eventToEdit.StartDateTime = model.StartDateTime; eventToEdit.Duration = model.Duration; eventToEdit.Description = model.Description; eventToEdit.Address = model.Address; eventToEdit.City = model.City; eventToEdit.State = model.State; eventToEdit.Zip = zip > 9999 ? new Nullable<int>(zip) : null; eventToEdit.IsPublic = model.IsPublic; this.db.SaveChanges(); this.AddNotification("Event edited.", NotificationType.INFO); return this.RedirectToAction("My"); } return this.View(model); }