public VideosDO MapAllVideos(DataRow dataRow) { try { VideosDO video = new VideosDO(); //Check to see if database object is null if (dataRow["VideoID"] != DBNull.Value) { video.VideoID = (Int64)dataRow["VideoID"]; } video.VideoName = dataRow["Videoname"].ToString(); video.VideoPath = dataRow["VideoPath"].ToString(); video.VideoDescription = dataRow["VideoDescription"].ToString(); video.MunitionID = (Int64)dataRow["MunitionID"]; //video.UserID = (Int64)dataRow["UserID"]; return(video); } catch (Exception ex) { VideosErrorHandler("fatal", "UserDAO", "MapAllVideos", ex.Message, ex.StackTrace); throw ex; } }
public List <VideosDO> ViewVideos(Int64 MunitionID) { try { List <VideosDO> videos = new List <VideosDO>(); using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand enterCommand = new SqlCommand("DISPLAY_VIDEOS_BY_MUNITION", conn); enterCommand.CommandType = CommandType.StoredProcedure; enterCommand.Parameters.AddWithValue("@MunitionID", MunitionID); conn.Open(); DataTable videoInfo = new DataTable(); using (SqlDataAdapter videosAdapter = new SqlDataAdapter(enterCommand)) { videosAdapter.Fill(videoInfo); videosAdapter.Dispose(); } foreach (DataRow row in videoInfo.Rows) { VideosDO mappedRow = MapAllVideos(row); videos.Add(mappedRow); } } return(videos); } catch (Exception ex) { VideosErrorHandler("fatal", "VideosDAO", "ViewAllMunitionVideos", ex.Message, ex.StackTrace); throw ex; } }
public void UploadVideo(VideosDO video) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand enterCommand = new SqlCommand("UPLOAD_VIDEO", conn); enterCommand.CommandType = CommandType.StoredProcedure; enterCommand.Parameters.AddWithValue("@VideoName", video.VideoName); enterCommand.Parameters.AddWithValue("@VideoPath", video.VideoPath); enterCommand.Parameters.AddWithValue("@VideoDescription", video.VideoDescription); enterCommand.Parameters.AddWithValue("@MunitionID", video.MunitionID); enterCommand.Parameters.AddWithValue("@UserID", video.UserID); conn.Open(); enterCommand.ExecuteNonQuery(); } } catch (Exception ex) { VideosErrorHandler("fatal", "VideosDAO", "CreateNewVideo", ex.Message, ex.StackTrace); throw ex; } }
public static VideosDO MapPOtoDO(VideosPO from) { VideosDO to = new VideosDO(); to.VideoID = from.VideoID; to.VideoName = from.VideoName; to.VideoPath = from.VideoPath; to.VideoDescription = from.VideoDescription; to.MunitionID = from.MunitionID; to.UserID = from.UserID; return(to); }
public static List <VideosDO> MapPOtoDO(List <VideosPO> from) { List <VideosDO> to = new List <VideosDO>(); if (from != null) { foreach (VideosPO item in from) { VideosDO mappedItem = MapPOtoDO(item); to.Add(mappedItem); } } return(to); }
public ActionResult Update(Int64 videoID, Int64 munitionID) { ActionResult oResponse = View(videoID); try { VideosDO videos = dataAccess.ViewVideosByID(videoID); VideosPO displayObject = VideosMapper.MapDOtoPO(videos); oResponse = View(displayObject); } catch (Exception ex) { TempData["Message"] = "Video could not be updated at this time."; } return(oResponse); }
public void UpdateVideo(VideosDO videos) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand enterCommand = new SqlCommand("UPDATE_VIDEO", conn); enterCommand.CommandType = CommandType.StoredProcedure; enterCommand.Parameters.AddWithValue(@"VideoID", videos.VideoID); enterCommand.Parameters.AddWithValue("@VideoName", videos.VideoName); enterCommand.Parameters.AddWithValue("@VideoDescription", videos.VideoDescription); conn.Open(); enterCommand.ExecuteNonQuery(); } } catch (SqlException ex) { VideosErrorHandler("fatal", "VideosDAO", "UpdateVideo", ex.Message, ex.StackTrace); throw ex; } }
public VideosDO ViewVideosByID(Int64 videoID) { VideosDO videos = new VideosDO(); try { //Instantiate SqlConnection using (SqlConnection conn = new SqlConnection(connectionString)) { //Creating a new SqlCommand to use a stored procedure. SqlCommand enterCommand = new SqlCommand("DISPLAY_VIDEOS_BY_ID", conn); enterCommand.CommandType = CommandType.StoredProcedure; enterCommand.Parameters.AddWithValue("@VideoID", videoID); conn.Open(); //Using SqlDataAdapter to get SQL table. DataTable videosInfo = new DataTable(); using (SqlDataAdapter videoAdapter = new SqlDataAdapter(enterCommand)) { videoAdapter.Fill(videosInfo); videoAdapter.Dispose(); } //Mapping row to munition foreach (DataRow row in videosInfo.Rows) { videos = MapAllVideos(row); } } } catch (Exception ex) { VideosErrorHandler("fatal", "MunitionsDAO", "ViewMunitionsByID", ex.Message, ex.StackTrace); throw ex; } return(videos); }
public ActionResult UploadFile(HttpPostedFileBase uploadedFile, VideosDO video, Int64 munitionID) { ActionResult oResponse = RedirectToAction("Index", "Videos", new { munitionID }); if (ModelState.IsValid) { try { if (uploadedFile != null /* && uploadedFile.ContentType == ".mp4"*/) { string pathToSaveTo = Path.Combine(Server.MapPath("/Files/"), uploadedFile.FileName); pathToSaveTo = pathToSaveTo.Replace("\"", "/").Replace("\\", "//"); uploadedFile.SaveAs(pathToSaveTo); video.UserID = (Int64)Session["UserID"]; video.VideoPath = "~/Files/" + uploadedFile.FileName; } dataAccess.UploadVideo(video); } catch (Exception ex) { } } return(oResponse); }
public ActionResult Update(VideosPO form) { //Declaring local variables ActionResult oResponse = RedirectToAction("Index", "Videos", new { form.VideoID, form.MunitionID }); if (ModelState.IsValid) { try { VideosDO dataObject = VideosMapper.MapPOtoDO(form); dataAccess.UpdateVideo(dataObject); TempData["Message"] = $"Successfully updated video"; } catch (Exception ex) { oResponse = View(form); } } else { oResponse = View(form); } return(oResponse); }