Exemplo n.º 1
0
        public ActionResult Create(SitePage page, HttpPostedFileBase image)
        {
            page.CreatedUserId = User.Identity.GetUserId();

            ModelState.Clear();
            TryValidateModel(page);

            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(page.Slug))
                    {
                        page.Slug = VITV.Web.Helpers.UrlHelper.URLFriendly(page.Title);
                    }
                    page.Date = DateTime.Now;
                    db.SitePages.Add(page);
                    db.SaveChanges();
                    return(RedirectToAction("Management"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            return(View(page));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] TVCCompanyGroup tVCCompanyGroup)
        {
            if (ModelState.IsValid)
            {
                db.TVCCompanyGroups.Add(tVCCompanyGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tVCCompanyGroup));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,CompanyId")] TVCProduct tVCProduct)
        {
            if (ModelState.IsValid)
            {
                db.TVCProducts.Add(tVCProduct);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.TVCCompanies, "Id", "Name", tVCProduct.CompanyId);
            return(View(tVCProduct));
        }
Exemplo n.º 4
0
        public ActionResult Edit(CreateRoleModel model)
        {
            if (!String.IsNullOrEmpty(model.Name))
            {
                var role = AutoMapper.Mapper.Map <CreateRoleModel, IdentityRole>(model);
                context.Entry(role).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();

                return(RedirectToAction("Management"));
            }
            return(View(model));
        }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            //string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
            //string storagePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain];

            var errorVideos = new List <Video>();

            using (new Impersonator("uploaduser", "", "Upload@@123"))
            {
                foreach (Video video in context.Videos.ToList())
                {
                    var path = GetPhysicalPath(video.Url);
                    if (!System.IO.File.Exists(path))
                    {
                        errorVideos.Add(video);
                    }
                }
            }
            var  now             = DateTime.Now.Date;
            bool hasSchedule     = context.ProgramScheduleDetails.Any(p => DbFunctions.TruncateTime(p.DateTime) == now);
            var  modNotification = context.Infoes.Find("modnotification");

            if (modNotification == null)
            {
                modNotification = new Info
                {
                    Id          = "modnotification",
                    Title       = "Thông báo tới quản lý",
                    Description = ""
                };
                context.Infoes.Add(modNotification);
                context.SaveChanges();
            }
            DashboardView viewModel = new DashboardView()
            {
                ReporterCount = context.Employees.Count(),
                VideoCount    = context.Videos.Count(),
                //VideoStorage = GetDirectorySize(storagePath),
                ArticleCount    = context.Articles.Count(),
                ErrorVideos     = errorVideos,
                HasSchedule     = hasSchedule,
                ModNotification = modNotification.Description,
                HLAlls          = context.ArticleHighlightAlls.ToList(),
                HLCats          = context.ArticleHighlightCats.ToList()
            };

            return(View(viewModel));
            //return RedirectToAction("Management", "Video");
        }
Exemplo n.º 6
0
        public static bool CanAccess(this IPrincipal principal, string actionName, string controllerName, string site)
        {
            var context          = new VITVContext();
            var controllerAction = context.ControllerActions.FirstOrDefault(ca => ca.ActionName == actionName && ca.ControllerName == controllerName && ca.Site == site);

            if (controllerAction == null)
            {
                context.ControllerActions.Add(new ControllerAction
                {
                    Site           = site,
                    ActionName     = actionName,
                    ControllerName = controllerName
                });
                context.SaveChanges();
                return(false);
            }

            var controllerActionPermission = context.ControllerActionPermissions.Where(p => p.ControllerActionId == controllerAction.Id).ToList().FirstOrDefault(p => principal.IsInRole(p.Role.Name));

            if (controllerActionPermission != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
 public void Save()
 {
     try
     {
         _context.SaveChanges();
     }
     catch (OptimisticConcurrencyException)
     {
         //context.Refresh(System.Data.Entity.Core.Objects.RefreshMode.ClientWins, context.Infos);
         //context.SaveChanges();
     }
 }
Exemplo n.º 8
0
        public ActionResult Comment(CommentModel model)
        {
            var db      = new VITVContext();
            var comment = new ArticleComment
            {
                ArticleId   = model.ArticleId,
                Content     = model.Content,
                UserId      = User.Identity.GetUserId(),
                CreatedTime = DateTime.Now,
                Id          = model.Id
            };

            db.ArticleComments.Add(comment);
            db.SaveChanges();
            return(Json(new { success = true }));
        }
Exemplo n.º 9
0
        public ActionResult DeleteComments(List <string> comments)
        {
            if (comments != null)
            {
                var db = new VITVContext();
                foreach (var cmtId in comments)
                {
                    var comment = db.ArticleComments.Find(cmtId);
                    if (comment != null)
                    {
                        db.ArticleComments.Remove(comment);
                    }
                }
                db.SaveChanges();
            }

            return(Json(new { success = true }));
        }
Exemplo n.º 10
0
 public ActionResult AddReplies(List <ReplyModel> replies)
 {
     if (replies != null)
     {
         var db = new VITVContext();
         foreach (var replyModel in replies)
         {
             var reply = new ArticleCommentReply
             {
                 ArticleCommentId = replyModel.CommentId,
                 Content          = replyModel.Content,
                 UserId           = User.Identity.GetUserId(),
                 CreatedTime      = DateTime.Now
             };
             db.ArticleCommentReplies.Add(reply);
         }
         db.SaveChanges();
     }
     return(Json(new { success = true }));
 }
Exemplo n.º 11
0
 public ActionResult AddComments(List <CommentModel> comments)
 {
     if (comments != null)
     {
         var db = new VITVContext();
         foreach (var cmt in comments)
         {
             var comment = new ArticleComment
             {
                 ArticleId   = cmt.ArticleId,
                 Content     = cmt.Content,
                 UserId      = User.Identity.GetUserId(),
                 CreatedTime = DateTime.Now,
                 Id          = cmt.Id
             };
             db.ArticleComments.Add(comment);
         }
         db.SaveChanges();
     }
     return(Json(new { success = true }));
 }
Exemplo n.º 12
0
 public void Save()
 {
     _context.SaveChanges();
 }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            //checkThumbnailFiles();
            //checkReporterPhotos();
            //checkVideoCategoryPhotos();
            //checkVideoFiles();
            Console.WriteLine("Start");
            try
            {
                Console.WriteLine("Start 1");
                var context = new VITVContext();
                Console.WriteLine(context.Videos.Count());

                foreach (var video in context.Videos)
                {
                    if (video.Duration.TotalSeconds != 0)
                    {
                        break;
                    }
                    Console.WriteLine(video.Url);
                    var videoPath = GetPhysicalPath(video.Url);
                    Console.WriteLine(videoPath);
                    if (videoPath != "")
                    {
                        string ffMPEG   = @"\\10.0.0.10\web\FFmpeg\ffmpeg.exe";
                        string username = "******";
                        string password = "******";
                        System.Security.SecureString ssPwd = new System.Security.SecureString();
                        for (int x = 0; x < password.Length; x++)
                        {
                            ssPwd.AppendChar(password[x]);
                        }
                        string vArgs = string.Format("-i \"{0}\"", videoPath);

                        var thumbProc = new Process
                        {
                            StartInfo =
                            {
                                FileName               = ffMPEG,
                                Arguments              = vArgs,
                                UseShellExecute        = false,
                                CreateNoWindow         = true,
                                UserName               = username,
                                Password               = ssPwd,
                                LoadUserProfile        = false,
                                RedirectStandardOutput = false,
                                WorkingDirectory       = Path.GetDirectoryName(videoPath), //important: http://stackoverflow.com/questions/990562/win32exception-the-directory-name-is-invalid
                                RedirectStandardError  = true
                            }
                        };

                        try
                        {
                            thumbProc.Start();
                            var SROutput = thumbProc.StandardError;
                            var outPut   = SROutput.ReadToEnd();

                            var re = new System.Text.RegularExpressions.Regex("[D|d]uration:.((\\d|:|\\.)*)");
                            var m  = re.Match(outPut);

                            thumbProc.WaitForExit();
                            thumbProc.Close();

                            if (m.Success)
                            {
                                //Means the output has cantained the string "Duration"
                                string   temp       = m.Groups[1].Value;
                                string[] timepieces = temp.Split(new char[] { ':', '.' });
                                if (timepieces.Length == 4)
                                {
                                    // Store duration
                                    var videoDuration = new TimeSpan(0, Convert.ToInt16(timepieces[0]), Convert.ToInt16(timepieces[1]), Convert.ToInt16(timepieces[2]), Convert.ToInt16(timepieces[3]));
                                    video.Duration = videoDuration;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Error: " + ex.Message);
                        }
                    }
                    Console.WriteLine(video.Id);
                }
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            Console.WriteLine("Completed");
            Console.ReadLine();
        }