コード例 #1
0
        public ActionResult Manage(Service service)
        {
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (ModelState.IsValid)
            {
                if (service.Id == 0)
                {
                    var         loggedInUserId = User.Identity.GetUserId();
                    FuneralHome home           = db.FuneralHomes.Where(f => f.UserId == loggedInUserId).FirstOrDefault();
                    service.FuneralHome = home;
                    service             = db.Services.Add(service);
                    db.SaveChanges();
                }
                else
                {
                    //Not sure why lazy load isn't working here
                    Video vid = db.Videos.Find(service.Id);
                    if (vid != null)
                    {
                        if (service.Video != null && User.IsInRole("Admin"))
                        {
                            if (service.Video.Status != null)
                            {
                                Video serviceVid = db.Videos.Find(service.Id);
                                serviceVid.Status            = service.Video.Status;
                                serviceVid.ConvertedFilePath = service.Video.ConvertedFilePath;
                                db.Entry(serviceVid).State   = EntityState.Modified;
                                service.Video = serviceVid;
                            }
                        }
                        Service dbService = db.Services.AsNoTracking().Where(x => x.Id == service.Id).FirstOrDefault();
                        if (dbService != null)
                        {
                            //Don't allow user to change anything if we are currently rendering a video
                            var videoQs = db.VideoQueues.Where(s => s.VideoId == service.Id).FirstOrDefault();
                            if (videoQs != null)
                            {
                                ModelState.Clear();
                                ModelState.AddModelError("RenderInProgress", "Cannot save changes because the video is rendering. Please wait for video to be done rendering, refresh the page and save your changes.");
                                return(View(dbService));
                            }

                            //Detect changes, and re render video if needed
                            if (service.HasSlate != dbService.HasSlate)
                            {
                                AzureRender.CopyProductionVideoToQueContainer(dbService.Video.ConvertedFilePath);
                                VideoQueType renderType = VideoQueType.StripSlate;
                                if (service.HasSlate)
                                {
                                    renderType = VideoQueType.AddSlate;
                                }
                                AzureRender.AssigningVideosToQueue(service.Id, dbService.Video.ConvertedFilePath, renderType);
                            }
                            else if (service.FirstName != dbService.FirstName || service.LastName != dbService.LastName || service.ServiceDate != dbService.ServiceDate)
                            {
                                if (service.HasSlate == true)
                                {
                                    AzureRender.CopyProductionVideoToQueContainer(dbService.Video.ConvertedFilePath);
                                    AzureRender.AssigningVideosToQueue(service.Id, dbService.Video.ConvertedFilePath, VideoQueType.ReEditSlate);
                                }
                            }
                        }
                    }
                    db.Entry(service).State = EntityState.Modified;
                    db.SaveChanges();
                }
                if (service.IsSecured && service.ViewingUserId == null)
                {
                    SecuredServiceHelper servHelp = new SecuredServiceHelper();
                    servHelp.MakeServiceSecure(service, db);
                }
                return(RedirectToAction("Manage", new { id = service.Id }));
            }
            return(View(service));
        }
コード例 #2
0
        public ActionResult UploadFilesToAzure(string[] fileNames, string container)
        {
            AzureRender.UploadFilesToAzure(fileNames, container);

            return(Json(new { result = "bla" }));
        }