private static Activity LoadData(ActivityEditDTO data) { var activityEntity = new Activity { ActivityId = data.Id, ActivityName = data.Name, ActivityDescription = data.Description, RequiresApproval = data.RequiresApproval, CreateEmployeeId = data.CreateEmployeeId }; return activityEntity; }
public ActivityEditDTO Insert(ActivityEditDTO data) { using (var ctx = new Entities()) { ctx.Database.Connection.Open(); var saveActivity = LoadData(data); ctx.Activities.Add(saveActivity); ctx.SaveChanges(); data.Id = saveActivity.ActivityId; } return data; }
public ActivityEditDTO Update(ActivityEditDTO data) { using (var ctx = new Entities()) { ctx.Database.Connection.Open(); var saveActivity = LoadData(data); ctx.Activities.Attach(saveActivity); var objectState = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager; objectState.GetObjectStateEntry(saveActivity).SetModifiedProperty("ActivityName"); objectState.GetObjectStateEntry(saveActivity).SetModifiedProperty("ActivityDescription"); objectState.GetObjectStateEntry(saveActivity).SetModifiedProperty("RequiresApproval"); objectState.GetObjectStateEntry(saveActivity).SetModifiedProperty("CreateEmployeeId"); ctx.SaveChanges(); data.Id = saveActivity.ActivityId; } return data; }
public ActivityEditDTO Insert(ActivityEditDTO data) { throw new NotImplementedException(); }
public Task<ActivityEditDTO> GetActivityByIdAsync(int activityEditId) { var dto = new ActivityEditDTO { Id = activityEditId, RequiresApproval = activityEditId == ItemRequiresApproval }; return Task.FromResult(dto); }