public void DeleteItem(TrackInfo i) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository<TrackInfo>(); rep.Delete(i); } }
public void UpdateItem(TrackInfo i) { repo.UpdateItem(i); }
public void CreateItem(TrackInfo i) { repo.CreateItem(i); }
public void DeleteItem(TrackInfo i) { repo.DeleteItem(i); }
public HttpResponseMessage UpdateTrack(TrackInfo track) { try { var updatesToProcess = false; var originalTrack = TrackDataAccess.GetItem(track.TrackId, track.CodeCampId); if (!string.Equals(track.Title, originalTrack.Title)) { originalTrack.Title = track.Title; updatesToProcess = true; } if (!string.Equals(track.Description, originalTrack.Description)) { originalTrack.Description = track.Description; updatesToProcess = true; } if (originalTrack.CustomProperties != null) { // parse custom properties for updates foreach (var property in originalTrack.CustomPropertiesObj) { if (track.CustomPropertiesObj.Any(p => p.Name == property.Name)) { // see if the existing property needs to be updated var prop = track.CustomPropertiesObj.FirstOrDefault(p => p.Name == property.Name); if (!string.Equals(prop.Value, property.Value)) { property.Value = prop.Value; updatesToProcess = true; } } else { // delete the property originalTrack.CustomPropertiesObj.Remove(property); updatesToProcess = true; } } } if (track.CustomPropertiesObj != null) { // add any new properties if (originalTrack.CustomProperties == null) { foreach (var property in track.CustomPropertiesObj) { originalTrack.CustomPropertiesObj.Add(property); updatesToProcess = true; } } else { foreach (var property in track.CustomPropertiesObj.Where(property => !originalTrack.CustomPropertiesObj.Contains(property))) { originalTrack.CustomPropertiesObj.Add(property); updatesToProcess = true; } } } if (updatesToProcess) { originalTrack.LastUpdatedByDate = DateTime.Now; originalTrack.LastUpdatedByUserId = UserInfo.UserID; TrackDataAccess.UpdateItem(originalTrack); } var savedTrack = TrackDataAccess.GetItem(track.TrackId, track.CodeCampId); var response = new ServiceResponse<TrackInfo> { Content = savedTrack }; return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()); } catch (Exception ex) { Exceptions.LogException(ex); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE); } }
public HttpResponseMessage CreateTrack(TrackInfo track) { try { var timeStamp = DateTime.Now; track.CreatedByDate = timeStamp; track.CreatedByUserId = UserInfo.UserID; track.LastUpdatedByDate = timeStamp; track.LastUpdatedByUserId = UserInfo.UserID; TrackDataAccess.CreateItem(track); var tracks = TrackDataAccess.GetItems(track.CodeCampId); var savedTrack = tracks.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.Title == track.Title); var response = new ServiceResponse<TrackInfo> { Content = savedTrack }; return Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()); } catch (Exception ex) { Exceptions.LogException(ex); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE); } }