public void UpdateItem(TimeSlotInfo i) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <TimeSlotInfo>(); rep.Update(i); } }
public void DeleteItem(TimeSlotInfo i) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository<TimeSlotInfo>(); rep.Delete(i); } }
public TimeSlotInfo GetItem(int itemId, int codeCampId) { TimeSlotInfo i = null; using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <TimeSlotInfo>(); i = rep.GetById(itemId, codeCampId); } return(i); }
public AgendaTimeSlotInfo(TimeSlotInfo timeSlot) { TimeSlotId = timeSlot.TimeSlotId; CodeCampId = timeSlot.CodeCampId; BeginTime = timeSlot.BeginTime; EndTime = timeSlot.EndTime; AgendaText = timeSlot.AgendaText; SpanAllTracks = timeSlot.SpanAllTracks; IncludeInDropDowns = timeSlot.IncludeInDropDowns; CreatedByUserId = timeSlot.CreatedByUserId; CreatedByDate = timeSlot.CreatedByDate; LastUpdatedByDate = timeSlot.LastUpdatedByDate; LastUpdatedByUserId = timeSlot.LastUpdatedByUserId; CustomProperties = timeSlot.CustomProperties; }
public void DeleteItem(TimeSlotInfo i) { repo.DeleteItem(i); }
public void CreateItem(TimeSlotInfo i) { repo.CreateItem(i); }
public void UpdateItem(TimeSlotInfo i) { repo.UpdateItem(i); }
private bool TimeSlotHasUpdates(ref TimeSlotInfo originalTimeSlot, ref TimeSlotInfo timeSlot) { var updatesToProcess = false; if (timeSlot.BeginTime != originalTimeSlot.BeginTime) { originalTimeSlot.BeginTime = timeSlot.BeginTime; updatesToProcess = true; } if (timeSlot.EndTime != originalTimeSlot.EndTime) { originalTimeSlot.EndTime = timeSlot.EndTime; updatesToProcess = true; } if (!string.Equals(timeSlot.AgendaText, originalTimeSlot.AgendaText)) { originalTimeSlot.AgendaText = timeSlot.AgendaText; updatesToProcess = true; } if (timeSlot.SpanAllTracks != originalTimeSlot.SpanAllTracks) { originalTimeSlot.SpanAllTracks = timeSlot.SpanAllTracks; updatesToProcess = true; } if (timeSlot.IncludeInDropDowns != originalTimeSlot.IncludeInDropDowns) { originalTimeSlot.IncludeInDropDowns = timeSlot.IncludeInDropDowns; updatesToProcess = true; } if (originalTimeSlot.CustomProperties != null) { // parse custom properties for updates foreach (var property in originalTimeSlot.CustomPropertiesObj) { if (timeSlot.CustomPropertiesObj.Any(p => p.Name == property.Name)) { // see if the existing property needs to be updated var prop = timeSlot.CustomPropertiesObj.FirstOrDefault(p => p.Name == property.Name); if (!string.Equals(prop.Value, property.Value)) { property.Value = prop.Value; updatesToProcess = true; } } else { // delete the property originalTimeSlot.CustomPropertiesObj.Remove(property); updatesToProcess = true; } } } if (timeSlot.CustomPropertiesObj != null) { // add any new properties if (originalTimeSlot.CustomProperties == null) { foreach (var property in timeSlot.CustomPropertiesObj) { originalTimeSlot.CustomPropertiesObj.Add(property); updatesToProcess = true; } } else { TimeSlotInfo slot = originalTimeSlot; foreach (var property in timeSlot.CustomPropertiesObj.Where(property => !slot.CustomPropertiesObj.Contains(property))) { slot.CustomPropertiesObj.Add(property); updatesToProcess = true; } } } return updatesToProcess; }
public HttpResponseMessage UpdateTimeSlot(TimeSlotInfo timeSlot) { try { var updatesToProcess = false; var originalTimeSlot = TimeSlotDataAccess.GetItem(timeSlot.TimeSlotId, timeSlot.CodeCampId); updatesToProcess = TimeSlotHasUpdates(ref originalTimeSlot, ref timeSlot); if (updatesToProcess) { originalTimeSlot.LastUpdatedByDate = DateTime.Now; originalTimeSlot.LastUpdatedByUserId = UserInfo.UserID; TimeSlotDataAccess.UpdateItem(originalTimeSlot); } var savedTimeSlot = TimeSlotDataAccess.GetItem(timeSlot.TimeSlotId, timeSlot.CodeCampId); // removing this prevented the saved/retrieved time from being offset to being about 4 hours off //if (savedTimeSlot != null) //{ // savedTimeSlot.BeginTime = savedTimeSlot.BeginTime.ToLocalTime(); // savedTimeSlot.EndTime = savedTimeSlot.EndTime.ToLocalTime(); //} var response = new ServiceResponse<TimeSlotInfo> { Content = savedTimeSlot }; return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()); } catch (Exception ex) { Exceptions.LogException(ex); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE); } }
public HttpResponseMessage CreateTimeSlot(TimeSlotInfo timeSlot) { try { var timeStamp = DateTime.Now; timeSlot.CreatedByDate = timeStamp; timeSlot.CreatedByUserId = UserInfo.UserID; timeSlot.LastUpdatedByDate = timeStamp; timeSlot.LastUpdatedByUserId = UserInfo.UserID; TimeSlotDataAccess.CreateItem(timeSlot); var timeSlots = TimeSlotDataAccess.GetItems(timeSlot.CodeCampId); var savedTimeSlot = timeSlots.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.BeginTime == timeSlot.BeginTime); // removing this prevented the saved/retrieved time from being offset to being about 4 hours off //if (savedTimeSlot != null) //{ // savedTimeSlot.BeginTime = savedTimeSlot.BeginTime.ToLocalTime(); // savedTimeSlot.EndTime = savedTimeSlot.EndTime.ToLocalTime(); //} var response = new ServiceResponse<TimeSlotInfo> { Content = savedTimeSlot }; return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()); } catch (Exception ex) { Exceptions.LogException(ex); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE); } }