public HttpResponseMessage AddVideo(VideoInfo videoDto) { try { Requires.NotNull("videoDto", videoDto); Requires.NotNegative("videoDto.CourseId", videoDto.CourseId); Requires.NotNegative("videoDto.ModuleId", videoDto.ModuleId); Requires.NotNegative("videoDto.OrderIndex", videoDto.OrderIndex); Requires.NotNegative("videoDto.CreatedByUserId", videoDto.CreatedByUserId); Requires.NotNegative("videoDto.LastModifiedByUserId", videoDto.LastModifiedByUserId); if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName)) { var vc = new VideoController(); // get the video from the database to maintain data integrity var video = vc.GetVideo(videoDto.VideoId, videoDto.ModuleId); if (video == null) { // this is a new video // update all values video = new VideoInfo() { VimeoId = videoDto.VimeoId, CourseId = videoDto.CourseId, ModuleId = videoDto.ModuleId, OrderIndex = videoDto.OrderIndex, CreatedByUserId = videoDto.CreatedByUserId, LastModifiedByUserId = videoDto.LastModifiedByUserId, LastModifiedOnDate = DateTime.Now, CreatedOnDate = DateTime.Now }; vc.CreateVideo(video); } else { // this is an existing video that's getting updated // we'll only update the values that are allowed to be updated video.VimeoId = videoDto.VimeoId; video.CourseId = videoDto.CourseId; video.OrderIndex = videoDto.OrderIndex; video.LastModifiedByUserId = videoDto.LastModifiedByUserId; video.LastModifiedOnDate = DateTime.Now; vc.UpdateVideo(video); } } return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception exc) { Exceptions.LogException(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }
public HttpResponseMessage GetVideos(int moduleId) { try { Requires.NotNegative("moduleId", moduleId); var ctl = new VideoController(); var videos = ctl.GetVideos(moduleId).ToJson(); return Request.CreateResponse(HttpStatusCode.OK, videos); } catch (Exception exc) { Exceptions.LogException(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }
public HttpResponseMessage DeleteVideo(VideoInfo video) { try { Requires.NotNull("video", video); Requires.NotNegative("video.ModuleId", video.ModuleId); Requires.NotNegative("video.VideoId", video.VideoId); if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName)) { var vc = new VideoController(); //vc.DeleteVideo(video); vc.DeleteVideo(video.VideoId, video.ModuleId); return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.Forbidden); } } catch (Exception exc) { Exceptions.LogException(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }