private bool ConfirmAccount(string confirmationToken) { var context = new ApplicationDbContext(); var user = context.Users.SingleOrDefault(u => u.ConfirmationToken == confirmationToken); if (user != null) { user.IsConfirmed = true; var dbSet = context.Set<ApplicationUser>(); dbSet.Attach(user); context.Entry(user).State = EntityState.Modified; context.SaveChanges(); return true; } return false; }
public static List<Meeting> BookCheckedDates2(ApplicationDbContext context, ICurrentUser student, IEnumerable<PickMeeting> pickMeetings) { var meetingsBooked = new List<Meeting>(); foreach (var meeting in pickMeetings) { if (meeting.IsPicked) { var checkedMeeting = context.Meetings.Find(meeting.Id); //Create GoToMeeting var meetingUrl = CreateGtmForAvailableSlot(context, checkedMeeting); if (!string.IsNullOrEmpty(meetingUrl)) { checkedMeeting.GtmUrl = meetingUrl; checkedMeeting.MeetingTypeId = (int) MeetingType.PrivateMeeting; checkedMeeting.StudentId = student.User.Id; checkedMeeting.Title = checkedMeeting.Title + " - " + student.User.FirstNameLastInitial; context.Entry(checkedMeeting).State = EntityState.Modified; meetingsBooked.Add(checkedMeeting); } else { Log4NetHelper.Log("Meeting Booking Failed", LogLevel.WARN, "BookCheckedDates", 328, student.User.UserName, null); } } } try { context.SaveChanges(); } catch (Exception ex) { Log4NetHelper.Log("Failed to Book Meeting", LogLevel.ERROR, "Meetings", 150, student.User.UserName, ex); } return meetingsBooked; }
public ActionResult Update_MyAvailableTime([DataSourceRequest]DataSourceRequest request, MeetingViewModel task) { if (ModelState.IsValid) { using (var context = new ApplicationDbContext()) { // Create a new Task entity and set its properties from the posted TaskViewModel var entity = new Meeting { Id = task.Id, Title = task.Title, Start = task.Start, End = task.End, Description = task.Description, RecurrenceRule = task.RecurrenceRule, RecurrenceException = task.RecurrenceException, RecurrenceId = task.RecurrenceId, IsAllDay = task.IsAllDay, InstructorId = task.InstructorId, MeetingTypeId = task.MeetingTypeId }; // Attach the entity context.Meetings.Attach(entity); // Change its state to Modified so Entity Framework can update the existing task instead of creating a new one context.Entry(entity).State = EntityState.Modified; // Update the entity in the database try { // Insert the entity in the database context.SaveChanges(); } catch (Exception ex) { Log4NetHelper.Log("Error Updating Available Meeting Available Meeting", LogLevel.ERROR, "MeetingsServices", 497, "tester", ex); } } } // Return the updated task. Also return any validation errors. return Json(new[] { task }.ToDataSourceResult(request, ModelState)); }
public static List<Meeting> BookCheckedDates(ApplicationDbContext context, ICurrentUser student, AvailableMeetingsViewModel form, IEnumerable<AvailableMeeting> availableMeetings) { var bookedMeetings = form.CheckedAvailableMeetings; var meetingsBooked = new List<Meeting>(); var i = 0; foreach (var meeting in availableMeetings) { //var meetingId = meeting.Id; //var xtra = meeting.IsChecked; //if (model.CheckedAvailableMeetings[i]) if (meeting.IsChecked) { var checkedMeeting = context.Meetings.Find(meeting.Id); var studentName = student.User.FirstName + " " + student.User.LastName.Substring(0, 1) + "."; var instructorName = checkedMeeting.Instructor.FirstName + " " + checkedMeeting.Instructor.LastName.Substring(0, 1) + "."; //Create GoToMeeting var meetingUrl = CreateGtmForAvailableSlot(context, checkedMeeting); if (!string.IsNullOrEmpty(meetingUrl)) { checkedMeeting.GtmUrl = meetingUrl; checkedMeeting.MeetingTypeId = (int) MeetingType.PrivateMeeting; checkedMeeting.StudentId = student.User.Id; checkedMeeting.Title = checkedMeeting.Title + " - " + studentName; checkedMeeting.Description = studentName + " has booked an online meeting with " + instructorName + " on " + checkedMeeting.Start.AddMinutes(TimeDateServices.GetUtcOffSet()) .ToString("dddd MMM-d-yyyy h-mm tt"); context.Entry(checkedMeeting).State = EntityState.Modified; meetingsBooked.Add(checkedMeeting); } //else //{ // Log4NetHelper.Log("Meeting Booking Failed", LogLevel.WARN, "BookCheckedDates", 328, studentName, null); //} } i++; } try { context.SaveChanges(); } catch (Exception ex) { Log4NetHelper.Log("Failed to Book Meeting", LogLevel.ERROR, "Meetings", 150, "Tester", ex); } return meetingsBooked; }