Пример #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.Video u = new Model.Video
            {
                Video_Title = this.txtTitle.Text.Trim(),
                Video_Intro = this.txtContent.Text,
                Video_Path  = this.textIntro.Text.Trim(),
                Video_Image = upFileName(this.FileUpload1, "../../upload/Video/"),
            };
            var       res = VideoSvc.Add(u);
            ReturnMsg rm  = res > 0
                ? new ReturnMsg()
            {
                Code    = StatusCode.OK,
                Message = "新增用户信息成功",
                Data    = null
            }
                : new ReturnMsg()
            {
                Code    = StatusCode.Error,
                Message = "新增用户信息失败",
                Data    = null
            };

            Session["Msg"] = rm; //用于传递执行信息的
            Response.Redirect("Video_List.aspx");
        }
        public ActionResult VideoSave(VideoViewModel viewModel, HttpPostedFileBase Thumbnail)
        {
            SessionKontrol();
            if (_users != null)
            {
                try
                {
                    if (viewModel.Thumbnail == null)
                    {
                        viewModel.Thumbnail = "0";
                    }
                    var isValid = Validate(viewModel, new VideoValidator(), ModelState);
                    if (isValid)
                    {
                        if (viewModel.Id == 0)
                        {
                            UploadFiles(Thumbnail);
                            viewModel.Thumbnail = imagename;
                            viewModel.Status    = true;

                            _VideoServices.Add(viewModel);
                        }
                        else
                        {
                            var getimg = _VideoServices.Get(viewModel.Id).Thumbnail;
                            if (viewModel.Thumbnail == "0")
                            {
                                viewModel.Thumbnail = getimg;
                                viewModel.Status    = true;
                                _VideoServices.Update(viewModel);
                            }
                            else
                            {
                                UploadFiles(Thumbnail);
                                viewModel.Thumbnail = "/Areas/Login/Assets/images/" + imagename;
                                _VideoServices.Update(viewModel);
                            }
                        }
                    }
                    else
                    {
                        if (viewModel.Id == 0)
                        {
                            return(View("videoadd", viewModel));
                        }
                        else
                        {
                            return(View("videodetail", viewModel));
                        }
                    }
                }
                catch (Exception)
                {
                    return(View(ViewForm, viewModel));
                }
                _unitOfWork.SaveChanges();
                return(RedirectToAction("VideoList", "Video"));
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }