public ActionResult removevlessons(int Id) { string Msg = "error"; Webinar_VideoL videols = db.Webinar_VideoL.Find(Id); try { if (videols != null) { if (videols.language == "ru") { Webinar_VideoXL VideoXl = db.Webinar_VideoXL.Find(videols.XId); if (VideoXl.Webinar_VideoL.Where(e => e.language != "ru").Count() == 0) { db.Webinar_VideoL.Remove(videols); Webinar_VideoLEM VideoLEMObj = db.Webinar_VideoLEM.Where(e => e.VideoXId == videols.XId).First(); db.Webinar_VideoLEM.Remove(VideoLEMObj); Webinar_VideoXL VideoXLObj = db.Webinar_VideoXL.Where(e => e.XId == videols.XId).First(); db.Webinar_VideoXL.Remove(VideoXLObj); db.SaveChanges(); Msg = "success"; } } else { db.Webinar_VideoL.Remove(videols); db.SaveChanges(); Msg = "success"; } } } catch { } return(Json(Msg)); }
public ActionResult createvlessons(Webinar_VideoL videols, int minute, string language, string XId, bool?publish) { if (language == null) { language = "ru"; } ViewBag.language = language; if (publish == null) { publish = false; } string Msg = "error"; try { videols.XId = Convert.ToDouble(XId.Replace(",", ".")); } catch { Msg = "warning02"; } HttpPostedFileBase file1 = Request.Files["img1"]; HttpPostedFileBase file2 = Request.Files["img2"]; Webinar_VideoL video = db.Webinar_VideoL.Where(e => e.language == language && e.XId == videols.XId).FirstOrDefault(); if (video == null) { try { if (file1.FileName != "" && file1 != null) { string ImageName = file1.FileName; videols.Iconimg = "~/Images/Webinar/" + language + "/" + DateTime.Now.Date.Year + DateTime.Now.Date.Month + DateTime.Now.Date.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "_" + ImageName.Replace(" ", "_"); file1.SaveAs(HttpContext.Server.MapPath(videols.Iconimg)); } if (file2.FileName != "" && file2 != null) { string ImageName = file2.FileName; videols.Iconimg2 = "~/Images/Webinar/" + language + "/" + DateTime.Now.Date.Year + DateTime.Now.Date.Month + DateTime.Now.Date.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "_" + ImageName.Replace(" ", "_"); file2.SaveAs(HttpContext.Server.MapPath(videols.Iconimg2)); } Webinar_VideoXL videoXL = db.Webinar_VideoXL.Where(e => e.XId == videols.XId).FirstOrDefault(); if (videoXL == null) { Webinar_VideoXL newVideoXL = new Webinar_VideoXL(); newVideoXL.XId = videols.XId; newVideoXL.Enable = (bool)publish; db.Webinar_VideoXL.Add(newVideoXL); Webinar_VideoLEM newVideLem = new Webinar_VideoLEM(); newVideLem.Eye = 0; newVideLem.Likes = 0; newVideLem.minute = minute; newVideLem.VideoXId = videols.XId; db.Webinar_VideoLEM.Add(newVideLem); } videols.Date = DateTime.Now.AddHours(5); db.Webinar_VideoL.Add(videols); db.SaveChanges(); Msg = "success"; } catch { } } else if (video != null) { Msg = "warning01"; } if (Msg != "success") { if (file1.FileName != "" && file1 != null) { string fullPath = Request.MapPath(videols.Iconimg); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (file2.FileName != "" && file2 != null) { string fullPath = Request.MapPath(videols.Iconimg2); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } } var VideoLessons = db.Webinar_VideoL.Where(e => e.language == "ru").ToList(); ViewBag.AddVideoMsg = Msg; return(View(VideoLessons)); }
// POST: api/Default public async Task <IHttpActionResult> Post([FromBody] Webinar_VideoLessonCs data) { ResponseUWebinar_VideoL response = new ResponseUWebinar_VideoL(); UWebinar_VideoLesson Webinar_VideoLesson = new UWebinar_VideoLesson(); string UserName = User.Identity.Name; UserInfo userinfo = await db.UserInfoes.FirstOrDefaultAsync(e => e.UserName == UserName); if (data == null) { return(BadRequest("data null")); } if (data.Id == null) { return(BadRequest("data null")); } Webinar_VideoL VideoL = await db.Webinar_VideoL.FindAsync(data.Id); if (VideoL == null) { return(BadRequest("VideoL Not found")); } if (VideoL.Webinar_VideoXL.Enable != true) { return(BadRequest("VideoL Disabled")); } try { int Like = 0; int View = 0; Webinar_VideoLEM videLem = VideoL.Webinar_VideoXL.Webinar_VideoLEM.FirstOrDefault(); if (videLem != null) { Like = videLem.Likes; View = videLem.Eye; } bool liked = false; bool viewed = false; Webinar_EyeV eye = userinfo.Webinar_EyeV.FirstOrDefault(e => e.VideoXId == VideoL.XId); if (eye != null) { viewed = true; } Webinar_LikeV like = userinfo.Webinar_LikeV.FirstOrDefault(e => e.VideoXId == VideoL.XId); if (like != null) { liked = true; } Webinar_VideoXL vlXID = await db.Webinar_VideoXL.Where(e => e.XId < VideoL.XId).OrderByDescending(e => e.XId).FirstOrDefaultAsync(); Webinar_VideoXL vnXID = await db.Webinar_VideoXL.Where(e => e.XId > VideoL.XId).OrderBy(e => e.XId).FirstOrDefaultAsync(); Webinar_VideoL vl = null; Webinar_VideoL vn = null; if (vlXID != null) { vl = await db.Webinar_VideoL.FirstOrDefaultAsync(e => e.XId == vlXID.XId && e.language == VideoL.language); if (vl != null) { Webinar_VideoLesson.previousId = vl.Id; } } if (vnXID != null) { vn = await db.Webinar_VideoL.FirstOrDefaultAsync(e => e.XId == vnXID.XId && e.language == VideoL.language); if (vn != null) { Webinar_VideoLesson.nextId = vn.Id; } } Webinar_VideoLesson.Id = VideoL.Id; Webinar_VideoLesson.lang = VideoL.language; Webinar_VideoLesson.Name = VideoL.Name; Webinar_VideoLesson.Link = VideoL.Link; Webinar_VideoLesson.Like = Like; Webinar_VideoLesson.View = View; Webinar_VideoLesson.Liked = liked; Webinar_VideoLesson.Viewed = viewed; Webinar_VideoLesson.nextId = vn.Id; response.status = "ok"; response.Webinar_VideoLesson = Webinar_VideoLesson; return(Json(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }