public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; if (context.Request.Files.Count > 0) { string videoName = context.Request.Files["videoFile"].FileName; string videoPath = context.Server.MapPath(@"../Upload/Videos"); string title = context.Request["Title"].ToString(); DateTime uploadTime = DateTime.Now; string uploadUser = context.Session["CurrentUser"].ToString(); Video video = new Video() { Url = "Upload//Videos//" + videoName, Title = title, UploadUser = uploadUser, UploadTime = uploadTime, }; if (VideoService.Create(video)) { HttpPostedFile postedFile = context.Request.Files["videoFile"]; postedFile.SaveAs(context.Request.MapPath("..//" + video.Url)); context.Response.Write("上传成功"); } else { context.Response.Write("上传失败"); } } }
public async Task <ActionResult> Register(RegisterModel model) { // await SetInitialDataAsync(); if (ModelState.IsValid) { UserDTO userDto = new UserDTO { Email = model.Email, Password = model.Password, Role = "user" }; OperationDetails operationDetails = await VideoService.Create(userDto); if (operationDetails.Succedeed) { int?par = 1; return(View("SuccessRegister")); } else { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } } return(View(model)); }
public ActionResult Add(VideoInfo oldModel, FormCollection fc) { bool isAdd = true; if (oldModel.Id > 0) { isAdd = false; } //判断标题是否为空 bool errors = false; //所选分类 oldModel.CategoryId = Utils.StrToInt(fc["select_column"], 0); if (oldModel.CategoryId == 0) { ModelState.AddModelError("CATNOTSELECTED", "请选择视频所属分类"); errors = true; } if (string.IsNullOrEmpty(oldModel.Title)) { ModelState.AddModelError("TITLEEMPTY", "标题不能为空"); errors = true; } if (!errors && ModelState.IsValid) { oldModel = VideoService.Create(oldModel); //完成,提示信息 if (isAdd) { ViewBag.Msg = "添加成功!<a href=\"add\">继续?</a><span class=\"ml10\">或</span><a href=\"list\" class=\"ml10\">返回</a>"; } else { ViewBag.Msg = "修改成功!<a href=\"add\">添加新视频?</a><span class=\"ml10\">或</span><a href=\"list\" class=\"ml10\">返回</a>"; } } //初始化栏目类别 var catList = VideoCatService.List().ToList(); ViewBag.CatList = catList; return(View(oldModel)); }
public IActionResult OnPostAsync() { if (VideoLink != null) { _videoService.Create(new Video { Resource_link = VideoLink, Details = new Details { Description = "cool vid" } }); return(RedirectToPage("/Media/Videos")); } if (!ModelState.IsValid) { return(Page()); } var album = ( AlbumSelect != null ? _albumService.Get(AlbumSelect) : new Album { Details = new Details { } } ); album.Resource_link = album.Id; if (AlbumName.Length > 0) { album.Details.Name = AlbumName; } foreach (var image in ImageSelect) { var filePath = Path.Combine(_environment.ContentRootPath, image.FileName); var memoryStream = new MemoryStream(); image.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); _imageBlobService.CreateBlob(memoryStream, image.FileName, album.Id).Wait(); } _albumService.Update(album.Id, album); return(RedirectToPage("/Media/Albums/View", new { id = album.Id })); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IVideoService, IVideoRepository>(); var model = new ApiVideoServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Video>())).Returns(Task.FromResult(new Video())); var service = new VideoService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VideoModelValidatorMock.Object, mock.DALMapperMockFactory.DALVideoMapperMock); CreateResponse <ApiVideoServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.VideoModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVideoServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Video>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VideoCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IVideoService, IVideoRepository>(); var model = new ApiVideoServerRequestModel(); var validatorMock = new Mock <IApiVideoServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiVideoServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new VideoService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALVideoMapperMock); CreateResponse <ApiVideoServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVideoServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VideoCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public ActionResult <Video> Create(Video video) { _videoService.Create(video); return(CreatedAtRoute("GetVideo", new { id = video.Id.ToString() }, video)); }