public async Task <StatusAction> Handle(Command request, CancellationToken cancellationToken) { try { var uploadVideoResult = new PhotoUploadResult(); if (request.Video != null) { uploadVideoResult = this.videoAccessor.AddVideo(request.Video); } var result = await this.services.InsertEntityAsync(new Lecture { Name = request.Name, Description = request.Description, Video = uploadVideoResult.Url, VideoId = uploadVideoResult.PublicId, SectionId = request.SectionId, VideoTime = request.VideoTime }); return(new CreateLectureSuccess(result.Id, result.Video, "bài học")); } catch (Exception) { throw new RestException(StatusCode.BadRequest, new { message = "Thêm bài học thất bại" }); } }
public void Update(string name, decimal price, PhotoUploadResult photo) { Name = name; Price = price; UrlPhoto = photo?.Url; PhotoPublicId = photo?.PublicId; Validar(); }
public void Update(string name, string gender, PhotoUploadResult photo) { Name = name; Gender = gender; PhotoUrl = photo?.Url; PhotoPublicId = photo?.PublicId; Validar(); }
public void Update(string name, string email, string phone, Address address, PhotoUploadResult photo) { Name = name; Email = email; Phone = phone; PhotoUrl = photo?.Url; PhotoPublicId = photo?.PublicId; Address?.Update(address?.Number, address?.Street, address?.Neighborhood, address?.City); Validar(); }
public TestFriend() { _photoUploadResult = new PhotoUploadResult { PublicId = "83247zsdsad", Url = "www.cloudinary.com/imagem/1" }; _address = new Address("10", "1234", "Eurico Salles", "Serra"); _user = new AppUser { Id = Guid.NewGuid().ToString(), UserName = "******", Email = "*****@*****.**" }; }
public async Task <StatusAction> Handle(Command request, CancellationToken cancellationToken) { try { var course = await this.coursesServices.GetByIdAsync(request.CourseId); if (course == null) { throw new NotFoundException("Không tìm thấy khóa học"); } var photoUploadResult = new PhotoUploadResult(); if (course.PhotoId == null) { photoUploadResult = photoAccessor.AddPhoto(request.File); course.Photo = photoUploadResult.Url; course.PhotoId = photoUploadResult.PublicId; await this.coursesServices.UpdateAsync(course, course.Id); } else { photoAccessor.DeletePhoto(course.PhotoId); photoUploadResult = photoAccessor.AddPhoto(request.File); course.Photo = photoUploadResult.Url; course.PhotoId = photoUploadResult.PublicId; await this.coursesServices.UpdateAsync(course, course.Id); } return(new UpdateImageSuccess() { Photo = photoUploadResult.Url }); } catch (Exception ex) { if (ex.GetType() == typeof(NotFoundException)) { throw new RestException(StatusCode.BadRequest, ex.Message); } throw new RestException(StatusCode.BadRequest, "Cập nhật thất bại"); } }
public async Task <ActionResult <AddEventPhotoResponseResource> > AddEventPhoto([FromForm] AddEventPhotoResource resource) { var evt = await UnitOfWork.Events.GetWithRelated(resource.EventId, e => e.Photos); if (evt == null) { throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found" }); } var userId = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); if (evt.HostId != userId) { throw new RestError(HttpStatusCode.NotFound, new { Event = "Event not found..." }); } PhotoUploadResult result = PhotoAccessor.AddPhoto(resource.File); bool isMain = !evt.Photos.Any(p => p.IsMain == true); Photo photo = new Photo() { CreatedAt = DateTime.Now, IsMain = isMain, PublicId = result.PublicId, Url = result.Url }; evt.Photos.Add(photo); await UnitOfWork.CompleteAsync(); var response = new AddEventPhotoResponseResource() { IsMain = isMain, PublicId = photo.PublicId, Url = photo.Url, EventId = evt.Id }; return(Ok(response)); }
public async Task <ActionResult <Photo> > postUploadResults(PhotoUploadResult result) { return(await Mediator.Send(new postUploadResults.Command { Result = result })); }
public void AddPhoto(PhotoUploadResult photo) { UrlPhoto = photo?.Url; PhotoPublicId = photo?.PublicId; Validar(); }