// //Конструктор. // public ArchiveDBControl() { InitializeComponent(); db = new CalendarContext(); db.DBArchiveEvents.Load(); dataGridView1.DataSource = db.DBArchiveEvents.Local.ToBindingList(); }
public AddClassTypeCommandValidator(CalendarContext dbContext) { RuleFor(x => x.NewClassType.Name) .NotEmpty() .MinimumLength(3) .MaximumLength(30); RuleFor(x => x.NewClassType.Name) .Must(n => !dbContext.ClassTypes.Any(c => c.Name == n)) .WithMessage(x => $"Class type name [ClassTypeName: {x.NewClassType.Name}] already in use."); RuleFor(x => x.NewClassType.Description) .NotEmpty() .MinimumLength(3) .MaximumLength(255); RuleFor(x => x.NewClassType.Limit) .NotEmpty() .GreaterThan(0); RuleFor(x => x.NewClassType.Room) .MinimumLength(3) .MaximumLength(30); RuleFor(x => x.NewClassType.Duration) .NotEmpty() .GreaterThan(0); }
public static List <Event> GetList() { using (var db = new CalendarContext()) { return(db.Events.ToList()); } }
public AddTimetableCommandValidator(CalendarContext dbContext) { RuleFor(x => x.NewTimetableDto.ClassTypeId) .GreaterThan(0); RuleFor(x => x.NewTimetableDto.ClassTypeId) .Must(id => dbContext.ClassTypes.Any(m => m.ClassTypeId == id)) .WithMessage(x => $"ClassType [ClassTypeId: {x.NewTimetableDto.ClassTypeId}] doesn't exists."); RuleFor(x => x.NewTimetableDto.StartingDate) .NotEmpty(); RuleFor(x => x.NewTimetableDto.StartingDate) .Must(startingDate => startingDate >= DateTime.Now) .WithMessage($"Select a date later than {DateTime.Now.ToShortDateString()}"); RuleFor(x => x.NewTimetableDto.EndingDate) .NotEmpty(); RuleFor(x => x.NewTimetableDto.EndingDate) .Must(endingDate => endingDate > DateTime.Now) .WithMessage("Select a date later than Timetable starting date"); RuleFor(x => x.NewTimetableDto.ClassesStartingTime) .NotEmpty(); RuleFor(x => x.NewTimetableDto.PeriodType) .NotEmpty(); RuleFor(x => x.NewTimetableDto.PeriodType) .Must(periodType => Enum.IsDefined(typeof(PeriodType), periodType)) .WithMessage("Available PeriodType: " + Enum.GetNames(typeof(PeriodType)) .Aggregate("", (current, value) => current + value + ", ")); }
// //Конструктор. // public AddHolidaysControl() { InitializeComponent(); db = new CalendarContext(); db.DBHolidays.Load(); dataGridView1.DataSource = db.DBHolidays.Local.ToBindingList(); }
public ActionResult Information(int Id) { CalendarContext calendarContext = new CalendarContext(); Calendar calendar = calendarContext.Calendars.Single(log => log.Id == Id); return(View(calendar)); }
public ActionResult Appointments() { var months = new[] { "", "Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sep.", "Oct", "Nov.", "Dec." }; using (CalendarContext db = new CalendarContext()) { var sales = db.Appointments .Where(a => a.StartDate.Year == DateTime.Now.Year) .Select(a => new { date = a.StartDate, value = a.Id }) .ToList(); return(Json( sales.GroupBy(a => a.date.Month) .Select(a => new { label = months[a.Key], value = a.Count() }) .ToList(), JsonRequestBehavior.AllowGet )); } }
private void SetUpClient() { var builder = new WebHostBuilder() .UseStartup <CalendarWebApi.Startup>() .ConfigureServices(services => { var context = new CalendarContext(new DbContextOptionsBuilder <CalendarContext>() .UseSqlite("DataSource=:memory:") .EnableSensitiveDataLogging() .Options); services.RemoveAll(typeof(CalendarContext)); services.AddSingleton(context); context.Database.OpenConnection(); context.Database.EnsureCreated(); context.SaveChanges(); // Clear local context cache foreach (var entity in context.ChangeTracker.Entries().ToList()) { entity.State = EntityState.Detached; } }); _server = new TestServer(builder); Client = _server.CreateClient(); }
public ActionResult AddCalendarEvent(string title, string description, string location, string start, string end, string allDay) { int newID; // Convert start and end to DateTime objects DateTime startTime = DateTime.ParseExact(start, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); DateTime endTime = DateTime.ParseExact(end, "dd-MM-yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Create CalendarEvent to be passed to database CalendarEvent calEvent = new CalendarEvent { FBID = (String)Session["FBID"], Title = title, Description = description, Location = location, StartTime = startTime, EndTime = endTime, Recurring = false, AllDay = Boolean.Parse(allDay) }; using (CalendarContext db = new CalendarContext()) { // Add CalendarEvent to database db.CalendarEvents.Add(calEvent); db.SaveChanges(); newID = calEvent.EventID; } // Return the new ID value so we can set it on the new calendar object return(Json(newID, JsonRequestBehavior.AllowGet)); }
// Get the calendar events for the logged in user and return them as JSON public ActionResult GetEventsForToday() { IList <CalendarDTO> eventList = new List <CalendarDTO>(); DateTime today = DateTime.Now; using (CalendarContext db = new CalendarContext()) { // For each calendar event, create a CalendarDTO object we can pass to the view as JSON foreach (CalendarEvent calEvent in db.CalendarEvents.ToList().Where(ce => (ce.StartTime.Day == today.Day || ce.EndTime.Day == today.Day) && ce.FBID == (String)Session["FBID"])) { eventList.Add(new CalendarDTO { id = calEvent.EventID, title = calEvent.Title, start = ToUnixTimespan(calEvent.StartTime), end = ToUnixTimespan(calEvent.EndTime), allDay = calEvent.AllDay, description = calEvent.Description, location = calEvent.Location }); } } return(Json(eventList, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Authorization /// </summary> /// <param name="code"></param> /// <returns></returns> public ActionResult Authorization(string code) { // Retrieve the authenticator and save it in session for future use var authenticator = GoogleAuthorizationHelper.GetAuthenticator(code); Session["authenticator"] = authenticator; // Save the refresh token locally using (var dbContext = new CalendarContext()) { var userName = User.Identity.Name; var userRegistry = dbContext.GoogleRefreshTokens.FirstOrDefault(c => c.UserName == userName); if (userRegistry == null) { dbContext.GoogleRefreshTokens.Add( new GoogleRefreshToken { UserName = userName, RefreshToken = authenticator.RefreshToken }); } else { userRegistry.RefreshToken = authenticator.RefreshToken; } dbContext.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public void TestCanCreate() { using (var c = new CalendarContext("Data Source=localhost;Initial Catalog=StaffCalendars;Integrated Security=True")) { var a = c.Appointments.Any(); } }
public ActionResult Admin() { CalendarContext calendarContext = new CalendarContext(); List <Calendar> calendars = calendarContext.Calendars.ToList(); return(View(calendars)); }
/// <summary> /// Run Seed if database is empty /// </summary> private void InitializeSeed() { var option = (DbContextOptions <CalendarContext>)_container.GetInstance(typeof(DbContextOptions <CalendarContext>), typeof(DbContextOptions <CalendarContext>).ToString()); var calendarContext = new CalendarContext(option); var seed = new Seed(calendarContext); seed.InitializeDB(); }
// //Конструктор. // public CreateCalendarControl() { InitializeComponent(); db = new CalendarContext(); db.DBCalendars.Load(); CheckHolidays(); dataGridView1.DataSource = db.DBCalendars.Local.ToBindingList(); }
// //Конструктор. // public CreateEventControl() { InitializeComponent(); db = new CalendarContext(); config = new Config(); db.DBEventDate.Load(); dataGridView1.DataSource = db.DBEventDate.Local.ToBindingList(); }
public ActionResult Edit(Calendar calendar) { CalendarContext calendarContext = new CalendarContext(); calendarContext.Entry(calendar).State = System.Data.Entity.EntityState.Modified; calendarContext.SaveChanges(); return(RedirectToAction("Admin")); }
public SignOutOfClassCommandValidator(CalendarContext dbContext) { RuleFor(x => x.ReservationId) .GreaterThan(0); RuleFor(x => x.ReservationId) .Must(id => dbContext.Reservations.Any(m => m.ReservationId == id)) .WithMessage(x => $"Reservation [ReservationId: {x.ReservationId}] not found."); }
public static void DeleteEvent(Event eventToDelete) { using (var db = new CalendarContext()) { var currentEvent = db.Events.FirstOrDefault(e => e.Id == eventToDelete.Id); db.Events.Remove(currentEvent); db.SaveChanges(); } }
public DeleteClassTypeCommandValidator(CalendarContext dbContext) { RuleFor(x => x.ClassTypeId) .GreaterThan(0); RuleFor(x => x.ClassTypeId) .Must(id => dbContext.ClassTypes.Any(m => m.ClassTypeId == id)) .WithMessage(x => $"Class type [ClassTypeId: {x.ClassTypeId}] not found"); }
public EditCalendarEventCommandHandlerTests() { var options = new DbContextOptionsBuilder <CalendarContext>() .UseInMemoryDatabase(databaseName: "Test") .Options; _context = new CalendarContext(options); _calendarEventRepository = new CalendarCalendarEventRepository(_context); }
public DeleteTimetableByIdCommandValidator(CalendarContext dbContext) { RuleFor(x => x.TimetableId) .GreaterThan(0); RuleFor(x => x.TimetableId) .Must(id => dbContext.Classes.Any(m => m.TimetableId == id)) .WithMessage(x => $"Timetable [TimetableId: {x.TimetableId}] not found"); }
public ContentResult Save(int?id, FormCollection actionValues) { var action = new DataAction(actionValues); var changedEvent = DHXEventsHelper.Bind <schedulerEvent>(actionValues); var entities = new CalendarContext(); var service = getService(); try { switch (action.Type) { case DataActionTypes.Insert: //System.Diagnostics.Debug.WriteLine(changedEvent.text); Event ge = service.Events.Insert(transformEvent(changedEvent), "primary").Execute(); changedEvent.user = User.Identity.GetUserName(); changedEvent.gid = ge.Id; entities.Events.Add(changedEvent); break; case DataActionTypes.Delete: // System.Diagnostics.Debug.WriteLine(changedEvent.gid); service.Events.Delete("primary", changedEvent.gid).Execute(); changedEvent = entities.Events.FirstOrDefault(ev => ev.gid.Equals(changedEvent.gid)); entities.Events.Remove(changedEvent); break; default: // "update" System.Diagnostics.Debug.WriteLine(changedEvent.gid); var target = entities.Events.Single(e => e.gid.Equals(changedEvent.gid)); DHXEventsHelper.Update(target, changedEvent, new List <string> { "id" }); target = entities.Events.Single(e => e.gid.Equals(changedEvent.gid)); var toUpdate = service.Events.Get("primary", target.gid).Execute(); toUpdate.Summary = target.text; toUpdate.Start = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = target.start_date.ToUniversalTime() }; toUpdate.End = new Google.Apis.Calendar.v3.Data.EventDateTime { DateTime = target.end_date.ToUniversalTime() }; service.Events.Update(toUpdate, "primary", toUpdate.Id).Execute(); break; } entities.SaveChanges(); action.TargetId = changedEvent.id; } catch (Exception) { action.Type = DataActionTypes.Error; } return(new AjaxSaveResponse(action)); }
public static Event AddEvent(Event newEvent) { using (var db = new CalendarContext()) { var book = db.Events.Add(newEvent); db.SaveChanges(); return(book); } }
public ActionResult DeleteConfirmed(int Id) { CalendarContext calendarContext = new CalendarContext(); Calendar calendar = calendarContext.Calendars.Single(log => log.Id == Id); calendarContext.Calendars.Remove(calendar); calendarContext.SaveChanges(); return(RedirectToAction("Admin")); }
public ActionResult Create(Calendar calendar) { if (ModelState.IsValid) { CalendarContext calendarContext = new CalendarContext(); calendarContext.Calendars.Add(calendar); calendarContext.SaveChanges(); return(RedirectToAction("Admin")); } return(View(calendar)); }
public static bool IsDatesExist(DateTime from, DateTime to, int?eventId) { using (var db = new CalendarContext()) { return(db.Events .Where(e => !eventId.HasValue || e.Id != eventId.Value) .Any(e => (from >= e.StartDate && from <= e.EndDate) || (to >= e.StartDate && to <= e.EndDate) || (from <= e.StartDate && to >= e.EndDate))); } }
public static Event UpdateEvent(Event newEvent) { using (var db = new CalendarContext()) { var currentEvent = db.Events.FirstOrDefault(e => e.Id == newEvent.Id); currentEvent.Name = newEvent.Name; currentEvent.StartDate = newEvent.StartDate; currentEvent.EndDate = newEvent.EndDate; db.SaveChanges(); return(currentEvent); } }
/// <summary> /// Helper method for creating inMemoryDb /// </summary> /// <param name="items">database items </param> /// <param name="dbName"> if not provided it will generate a ranom database-name </param> public static CalendarContext CreateInMemoryDB(List <CalendarEntrie> items, string dbName = null) { dbName = (dbName != null ? dbName : Guid.NewGuid().ToString()); var options = new DbContextOptionsBuilder <CalendarContext>() .UseInMemoryDatabase(databaseName: dbName) .Options; var context = new CalendarContext(options); items.ForEach(n => context.calendarEntries.Add(n)); context.SaveChanges(); return(context); }
public void TestUpsert() { using (var context = new CalendarContext("Data Source=localhost;Initial Catalog=StaffCalendars;Integrated Security=True")) { var cons = context.Rosters.FirstOrDefault(); if (cons == null) { cons = new ServerRoster { Id = Guid.Parse("D43880FF-6368-442D-85D6-01BB5CC6523C"), DepartmentName = "SS PICU", RosterName = "Consultants", Secret = HexadecimalStringToByteArray_Original("2CBC90D518D6066F579EC5E85F77C366D63FEF1616A4DD9D6646ED42BFC16C694B53221DB55627305213B3280F591EEB171610EE7013C20F76AB5057EA36A59E") //Convert.FromBase64String("hJ4blpw8qTI5PEFpdzM2cNpnf6qTNzSBys+x8zQjjojcrVLvPPrXbmpg1ICXgYAg7AprMxz5EiOId9qOR8avzw==") // 0x2CBC90D518D6066F579EC5E85F77C366D63FEF1616A4DD9D6646ED42BFC16C694B53221DB55627305213B3280F591EEB171610EE7013C20F76AB5057EA36A59E }; context.Rosters.Add(cons); context.SaveChanges(); } context.Upsert(new[] { new ServerStaffMember { /*Id = Guid.Parse("632036E2-C3CF-4116-B9B9-59AB075AB0DA"), */ FullName = "Alex Hussey", Roster = cons, StaffMemberCode = "AH" }, new ServerStaffMember { /*Id = Guid.Parse("1B435B77-0062-411F-9B6B-1B3C154D2E6D"), */ FullName = "Anusha Ganeshalingham", Roster = cons, StaffMemberCode = "AG" }, new ServerStaffMember { /*Id = Guid.Parse("BFE2AE9C-2C9A-4730-8D20-4BBC370461AB"), */ FullName = "Brent McSharry", Roster = cons, StaffMemberCode = "BM" }, new ServerStaffMember { /*Id = Guid.Parse("A1F39FFD-1161-4474-8823-8BB441395A2A"), */ FullName = "Fiona Miles", Roster = cons, StaffMemberCode = "M" }, new ServerStaffMember { /*Id = Guid.Parse("F4DE1C5A-AA18-4A99-B300-6183000CDC93"), */ FullName = "Gabrielle Nuthall", Roster = cons, StaffMemberCode = "N" }, new ServerStaffMember { /*Id = Guid.NewGuid(),*/ FullName = "Dave Buckley", Roster = cons, StaffMemberCode = "BU" }, new ServerStaffMember { /*Id = Guid.NewGuid(),*/ FullName = "John Beca", Roster = cons, StaffMemberCode = "BE" }, new ServerStaffMember { /*Id = Guid.NewGuid(),*/ FullName = "Brian Anderson", Roster = cons, StaffMemberCode = "A" }, new ServerStaffMember { /*Id = Guid.NewGuid(),*/ FullName = "Liz Segedin", Roster = cons, StaffMemberCode = "S" } }); } }
public void Insert() { using (var context = new CalendarContext(_credentials)) { // add the calendar var calendar = new Data.Tables.Calendar(); calendar.AuthorID = _credentials.UserID; calendar.Description = this.Description; calendar.Name = this.Name; context.Calendars.Add(calendar); context.SaveChanges(); this.CalendarID = calendar.ID; // Sharing foreach (var invitee in _calendarInvitees) { invitee.CalendarID = this.CalendarID; context.CalendarInvitees.Add(invitee); } // add the history record var history = new CalendarHistory(); history.CalendarID = this.CalendarID; history.TransactionDate = DateTime.Now; history.TransactionType = Data.Enumeration.CalendarHistoryType.Create; history.UserID = _credentials.UserID; context.CalendarHistory.Add(history); context.SaveChanges(); } }
private void _load(bool isLazyLoad) { using (var context = new CalendarContext(_credentials)) { var calendar = context.Calendars.Where(w => w.ID == this.CalendarID).FirstOrDefault(); if (calendar == null) { throw new iONCalendarException(this, "Calendar Not Found"); } // This is who the calendar is shared with _calendarInvitees = context.CalendarInvitees.Where(w => w.CalendarID == this.CalendarID).ToList(); if (_calendarEvents == null) { _calendarEvents = new List<iONCalendarEvent>(); } // load the events foreach (var e in context.Events.Where(w => w.CalendarID == this.CalendarID)) { var ionCalendarEvent = new iONCalendarEvent(_credentials, e); if (!isLazyLoad) { ionCalendarEvent.Load(e.ID); } _calendarEvents.Add(ionCalendarEvent); } // this is the ID of who created the calendar this.AuthorID = calendar.AuthorID; } }
public void Update() { using (var context = new CalendarContext(_credentials)) { // add the calendar var calendar = context.Calendars.Where(w => w.ID == this.CalendarID).First(); calendar.AuthorID = _credentials.UserID; calendar.Description = this.Description; calendar.Name = this.Name; // update the invitees // check id's to update? // add the history record var history = new CalendarHistory(); history.CalendarID = this.CalendarID; history.TransactionDate = DateTime.Now; history.TransactionType = Data.Enumeration.CalendarHistoryType.Edit; history.UserID = _credentials.UserID; context.CalendarHistory.Add(history); context.SaveChanges(); } }