Esempio n. 1
0
            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" });
                }
            }
Esempio n. 2
0
 public void Update(string name, decimal price, PhotoUploadResult photo)
 {
     Name          = name;
     Price         = price;
     UrlPhoto      = photo?.Url;
     PhotoPublicId = photo?.PublicId;
     Validar();
 }
Esempio n. 3
0
 public void Update(string name, string gender, PhotoUploadResult photo)
 {
     Name          = name;
     Gender        = gender;
     PhotoUrl      = photo?.Url;
     PhotoPublicId = photo?.PublicId;
     Validar();
 }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 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");
                }
            }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
 public async Task <ActionResult <Photo> > postUploadResults(PhotoUploadResult result)
 {
     return(await Mediator.Send(new postUploadResults.Command {
         Result = result
     }));
 }
Esempio n. 9
0
 public void AddPhoto(PhotoUploadResult photo)
 {
     UrlPhoto      = photo?.Url;
     PhotoPublicId = photo?.PublicId;
     Validar();
 }