public ActionResult Create([Bind(Include = "TrailMeetupID,Name,Description,ImageLink,Date,TimeFrom,TimeTo,Limit")] TrailMeetup trailMeetup, HttpPostedFileBase file, String[] text) { if (ModelState.IsValid) { LogWriter.Instance.LogInfo("TrailMeetupController / Create"); JoinTrail jointrail = new JoinTrail(); TrailMeetup_Location trailMeetup_Location = new TrailMeetup_Location(); // New TrailMeetup_Location Model() string path = Server.MapPath("~/Content/Upload/" + file.FileName); file.SaveAs(path); trailMeetup.ImageLink = file.FileName; trailMeetup.CreatorID = User.Identity.Name; DateTime currentTimeFrom = new DateTime(trailMeetup.Date.Year, trailMeetup.Date.Month, trailMeetup.Date.Day, trailMeetup.TimeFrom.Hour, trailMeetup.TimeFrom.Minute, 0, 0); trailMeetup.TimeFrom = currentTimeFrom; DateTime currentTimeTo = new DateTime(trailMeetup.Date.Year, trailMeetup.Date.Month, trailMeetup.Date.Day, trailMeetup.TimeTo.Hour, trailMeetup.TimeTo.Minute, 0, 0); trailMeetup.TimeTo = currentTimeTo; trailMeetupMapper.Insert(trailMeetup); // Insert the newly created TrailMeetup into DB // Get the Trail ID for the newly added Trail above int TrailID = trailMeetupMapper.getNewlyCreatedTrailID(trailMeetup.Name); if (text != null) { for (int i = 0; i < text.Length; i++) { trailMeetup_Location.TrailMeetupID = TrailID; // Convert the Location name to convert to the LocationID //trailMeetup_Location.LocationID = trailMeetupMapper.getLocationID(text[i]); trailMeetup_Location.LocationName = text[i]; trailMeetupLocationGateway.Insert(trailMeetup_Location); } } // TrailMeetup Creator is automatically enrolled a TrailMeetup Participant jointrail.TrailMeetupID = TrailID; jointrail.UserID = User.Identity.Name; joinTrailGateway.Insert(jointrail); return(RedirectToAction("Index")); } return(View(trailMeetup)); }
public ActionResult LeaveTrail(int id) { LogWriter.Instance.LogInfo("TrailMeetupController / LeaveTrail"); JoinTrail jointrail = new JoinTrail(); if (User.Identity.Name == null || User.Identity.Name == "") // Check is the username valid { return(HttpNotFound()); } else { // Delete user from the TrailMeetup joinTrailGateway.Delete(trailMeetupMapper.getUserJoinTrailForDelete(id, User.Identity.Name)); } return(RedirectToAction("Details_ViewModel", "TrailMeetup", new { id = id })); }
public ActionResult JoinTrail(int?id) { LogWriter.Instance.LogInfo("TrailMeetupController / JoinTrail"); JoinTrail jointrail = new JoinTrail(); if (User.Identity.Name == null || User.Identity.Name == "") // Check is the username valid { return(HttpNotFound()); } else { jointrail.TrailMeetupID = (int)id; jointrail.UserID = User.Identity.Name; } joinTrailGateway.Insert(jointrail); // Insert the new JoinTrail details into the DB return(RedirectToAction("Details_ViewModel", "TrailMeetup", new { id = id })); }