// GET: EVENTs/Details/5 public async Task <ActionResult> Details(short?id, short id_mem) { EVENTsViewModel eVENT = new EVENTsViewModel(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } eVENT.event_detail = await db.EVENT.FindAsync(id); eVENT.mem = await db.MEMBER.FindAsync(id_mem); //int i = 0; //if (db.PROMOTE_E.Count() < 4) //{ // i = db.PROMOTE_E.Count(); //} //else //{ // i = 4; //} DateTime today = DateTime.Today; DateTime b_day = Convert.ToDateTime(eVENT.mem.BIRTH_DATE.ToString()); int age = today.Year - b_day.Year; if (b_day > today.AddYears(-age)) { age--; } eVENT.event_for_promote = db.PROMOTE_E.Where(a => a.END_DATE > DateTime.Today && a.TARGET_MIN_AGE <age && a.TARGET_MAX_AGE> age).OrderBy(x => Guid.NewGuid()).Take(4).ToList();; if (eVENT == null) { return(HttpNotFound()); } return(View(eVENT)); }
public async Task <ActionResult> JoinAndPromote(short id, string user_name, EVENTsViewModel promote_event) { if (user_name != null) { EVENT eVENT = await db.EVENT.FindAsync(id); MEMBER mem = db.MEMBER.Where(u => u.USERNAME.Equals(user_name)).FirstOrDefault(); if (mem.EVENT.Where(a => a.EVENT_ID.Equals(eVENT.EVENT_ID)).FirstOrDefault() != null) { Response.Write("<script> alert('This member joined.')</script>"); return(RedirectToAction("Details", new { id = eVENT.EVENT_ID, id_mem = Session["id"] })); } UserCredential credential; using (var stream = new FileStream("../../Users/LekApinun/Documents/Visual Studio 2015/Projects/EVENT_VER5/PROJECT_DATABASE/EVENT_VER5/client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; //Console.WriteLine("Credential file saved to: " + credPath); } // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); string start = eVENT.TIME_START_E.ToString(); DateTime startT = Convert.ToDateTime(start); start = startT.Year.ToString() + '-' + startT.Month.ToString() + '-' + startT.Day.ToString() + 'T' + startT.TimeOfDay + "+07:00"; string end = eVENT.TIME_END_E.ToString(); DateTime endT = Convert.ToDateTime(end); end = endT.Year.ToString() + '-' + endT.Month.ToString() + '-' + endT.Day.ToString() + 'T' + endT.TimeOfDay + "+07:00"; Event newEvent = new Event() { Summary = eVENT.EVENT_NAME.ToString(), Location = eVENT.LOCATION.ToString(), Description = eVENT.DETAIL.ToString(), Start = new EventDateTime() { DateTime = DateTime.Parse(start), TimeZone = "Asia/Bangkok", }, End = new EventDateTime() { DateTime = DateTime.Parse(end), TimeZone = "Asia/Bangkok", }, Attendees = new EventAttendee[] { new EventAttendee() { Email = mem.E_MAIL.ToString(), ResponseStatus = "needsAction" } } }; String calendarId = "primary"; EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId); Event createdEvent = request.Execute(); //Console.WriteLine("Event created: {0}", createdEvent.HtmlLink); eVENT.MEMBER.Add(mem); await db.SaveChangesAsync(); return(RedirectToAction("Details", new { id = eVENT.EVENT_ID, id_mem = Session["id"] })); } else { EVENT eVENT = await db.EVENT.FindAsync(id); MEMBER mEMBER = await db.MEMBER.FindAsync(Session["id"]); promote_event.event_promote.PROMOTE_ID = (short)(db.PROMOTE_E.Count() + 1); promote_event.event_promote.END_DATE = DateTime.Today.AddDays(promote_event.day_of_promote); promote_event.event_promote.BUDGETS = promote_event.day_of_promote; promote_event.event_promote.MEMBER = mEMBER; promote_event.event_promote.EVENT.Add(eVENT); db.PROMOTE_E.Add(promote_event.event_promote); await db.SaveChangesAsync(); return(RedirectToAction("Details", new { id = eVENT.EVENT_ID, id_mem = Session["id"] })); } }