In this step, you'll create the Models used in your application.
To write code in C#
C# |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; |
To write code in C#
C# |
Copy Code
|
---|---|
public class EventObj { [Key] public int Id { get; set; } public string Subject { get; set; } public string Location { get; set; } public DateTime Start { get; set; } public DateTime End { get; set; } public string Description { get; set; } public bool AllDay { get; set; } } |
To write code in C#
C# |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; |
To write code in C#
C# |
Copy Code
|
---|---|
public static class EventAction { private static EventPlannerEntities _eventDb = new EventPlannerEntities(); internal static EventPlannerEntities GetEventDb() { return new EventPlannerEntities(); } public static IList<EventObj> GetEvents() { return _eventDb.Events.ToList(); } public static EventObj GetEventDetail(int id) { return _eventDb.Events.Find(id); } public static EventObj Create() { return new EventObj { Subject = "New event", Start = DateTime.Today, End = DateTime.Today.AddDays(1).AddSeconds(-1), AllDay = false }; } public static void Add(EventObj eventObj) { _eventDb.Events.Add(eventObj); _eventDb.SaveChanges(); } public static void Edit(EventObj eventObj) { _eventDb.Entry(eventObj).State = EntityState.Modified; _eventDb.SaveChanges(); } public static void Delete(int id) { EventObj eventObj = _eventDb.Events.Find(id); _eventDb.Events.Remove(eventObj); _eventDb.SaveChanges(); } } } |
To write code in C#
C# |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; |
To write code in C#
C# |
Copy Code
|
---|---|
public class EventPlannerEntities : DbContext { public DbSet<EventObj> Events { get; set; } public EventPlannerEntities() { Database.CreateIfNotExists(); } } } |