Exemplo n.º 1
0
        public ActionResult Create(HttpPostedFileBase thumbnailFile, VideoTVC videoTVC)
        {
            if (thumbnailFile != null && thumbnailFile.ContentLength > 0)
            {
                string extension           = Path.GetExtension(thumbnailFile.FileName);
                string timeUpload          = DateTime.Now.ToString("yyyyMMddHHmmss");
                string fileName            = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + thumbnailFile.FileName;
                string currentDomain       = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
                string folder              = "UploadedImages/VideoThumbnail";
                string physicalStoragePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain];
                string filePath            = physicalStoragePath + @"\" + folder + @"\" + fileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    thumbnailFile.SaveAs(filePath);
                }
                videoTVC.Thumbnail = currentDomain + "/" + folder + "/" + fileName;
            }

            ModelState.Clear();
            TryValidateModel(videoTVC);

            if (ModelState.IsValid)
            {
                _videoTVCRepository.InsertOrUpdate(videoTVC);
                _videoTVCRepository.Save();

                return(RedirectToAction("Management"));
            }
            ViewBag.ProductId      = new SelectList(_videoTVCRepository.AllProduct.ToList(), "Id", "Name");
            ViewBag.CompanyId      = new SelectList(_videoTVCRepository.AllCompany.ToList(), "Id", "Name");
            ViewBag.ProductGroupId = new SelectList(_videoTVCRepository.AllProductGroup.ToList(), "Id", "Name");
            ViewBag.CompanyGroupId = new SelectList(_videoTVCRepository.AllCompanyGroup.ToList(), "Id", "Name");
            return(View(videoTVC));
        }
Exemplo n.º 2
0
        public void InsertOrUpdate(VideoTVC videoTVC)
        {
            var model = _context.VideoTVCs.Find(videoTVC.Id);

            if (videoTVC.Id == default(int))
            {
                // New entity
                _context.VideoTVCs.Add(videoTVC);
            }
            else
            {
                // Existing entity
                _context.Entry(model).State    = EntityState.Detached;
                _context.Entry(videoTVC).State = EntityState.Modified;
            }
        }
Exemplo n.º 3
0
 public DbPropertyEntry GetProperty <TProperty>(VideoTVC videoTVC, Expression <Func <VideoTVC, TProperty> > property)
 {
     return(_context.Entry(videoTVC).Property(property));
 }
Exemplo n.º 4
0
 public void Load <TElement>(VideoTVC videoTVC, Expression <Func <VideoTVC, ICollection <TElement> > > includeProperty) where TElement : class
 {
     _context.VideoTVCs.Attach(videoTVC);
     _context.Entry(videoTVC).Collection(includeProperty).Load();
 }
Exemplo n.º 5
0
        public ActionResult Edit(HttpPostedFileBase thumbnailFile, VideoTVC videoTVC, string returnUrl)
        {
            string currentDomain       = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
            var    physicalStoragePath = System.Configuration.ConfigurationManager.AppSettings[currentDomain];

            //Thay thế file thumbnail
            if (thumbnailFile != null && thumbnailFile.ContentLength > 0)
            {
                //Xóa file thumbnail cũ
                string oldFilePath = VITV.Web.Helpers.UrlHelper.GetPhysicalPath(this, videoTVC.Thumbnail);
                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    if (System.IO.File.Exists(oldFilePath))
                    {
                        System.IO.File.Delete(oldFilePath);
                    }
                }

                string extension  = Path.GetExtension(thumbnailFile.FileName);
                string timeUpload = DateTime.Now.ToString("yyyyMMddHHmmss");
                string fileName   = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + thumbnailFile.FileName;
                string folder     = "UploadedImages/VideoThumbnail";
                string filePath   = physicalStoragePath + @"\" + folder + @"\" + fileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    thumbnailFile.SaveAs(filePath);
                }

                videoTVC.Thumbnail = currentDomain + "/" + folder + "/" + fileName;
            }

            ModelState.Clear();
            TryValidateModel(videoTVC);

            if (ModelState.IsValid)
            {
                var oldVideo = _videoTVCRepository.Find(videoTVC.Id);
                //Xóa video cũ
                if (oldVideo != null && oldVideo.Url != videoTVC.Url)
                {
                    string filePath = VITV.Web.Helpers.UrlHelper.GetPhysicalPath(this, oldVideo.Url);
                    using (new Impersonator("uploaduser", "", "Upload@@123"))
                    {
                        if (System.IO.File.Exists(filePath))
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }
                }

                _videoTVCRepository.InsertOrUpdate(videoTVC);
                _videoTVCRepository.Save();

                return(Json(new { success = true, id = videoTVC.Id }));
            }
            ViewBag.ProductId      = new SelectList(_videoTVCRepository.AllProduct.Where(p => p.CompanyId == videoTVC.Product.CompanyId).ToList(), "Id", "Name", videoTVC.ProductId);
            ViewBag.CompanyId      = new SelectList(_videoTVCRepository.AllCompany.ToList(), "Id", "Name", videoTVC.Product.CompanyId);
            ViewBag.ProductGroupId = new SelectList(_videoTVCRepository.AllProductGroup.ToList(), "Id", "Name", videoTVC.ProductGroupId);
            ViewBag.CompanyGroupId = new SelectList(_videoTVCRepository.AllCompanyGroup.ToList(), "Id", "Name", videoTVC.CompanyGroupId);
            return(Json(new{ success = false, view = this.RenderRazorViewToString("Edit", videoTVC) }));
        }