Пример #1
0
            public Result <Command> Handle(Query message)
            {
                var exhibit = _exhibitrepository.GetExhibit(message.Id);

                if (exhibit == null)
                {
                    return(Result.Fail <Command> ("Exhibit does not exit"));
                }
                if (exhibit.PhotographerId != message.UserId)
                {
                    return(Result.Fail <Command> ("Unauthorized"));
                }

                var command = new Command
                {
                    Id       = exhibit.Id,
                    Heading  = "Edit an Exhibit",
                    Genres   = _genrerepository.GetGenres(),
                    Date     = exhibit.DateTime.ToString("d MMM yyyy"),
                    GenreId  = exhibit.GenreId,
                    Location = exhibit.Location,
                    ImageUrl = _urlComposer.ComposeImgUrl(exhibit.ImageUrl)
                };

                return(Result.Ok(command));
            }
Пример #2
0
            public async Task <Result> Handle(Command message)
            {
                var exhibit = _repository.GetExhibit(message.Id);

                if (exhibit == null)
                {
                    return(Result.Fail <Command> ("Exhibit does not exit"));
                }
                if (exhibit.PhotographerId != message.UserId)
                {
                    return(Result.Fail <Command> ("Unauthorized"));
                }

                var uploadPath = Path.Combine(_environment.WebRootPath, "images/exhibits");

                if (message.ImageUpload != null)
                {
                    var ImageName = ContentDispositionHeaderValue.Parse(message.ImageUpload.ContentDisposition).FileName.Trim('"');
                    using (var fileStream = new FileStream(Path.Combine(uploadPath, message.ImageUpload.FileName), FileMode.Create))
                    {
                        await message.ImageUpload.CopyToAsync(fileStream);

                        message.ImageUrl = "http://exhibitbaseurl/images/exhibits/" + ImageName;
                    }
                }

                message.DateTime = DateTime.Parse(string.Format("{0}", message.Date));

                exhibit.UpdateDetails(message);
                _repository.SaveAll();

                return(Result.Ok());
            }
Пример #3
0
            public Result <int> Handle(Command message)
            {
                var exhibit = _exhibitRepository.GetExhibit(message.ExhibitId);

                if (exhibit == null)
                {
                    return(Result.Fail <int> ("Exhibit does not exit"));
                }
                var attendance = exhibit.Attendances.FirstOrDefault(a => a.AttendeeId == message.UserId);

                if (attendance == null)
                {
                    return(Result.Fail <int> ("Attendance does not exit"));
                }

                exhibit.RemoveAttendance(attendance);
                _exhibitRepository.SaveAll();

                return(Result.Ok(message.ExhibitId));
            }
Пример #4
0
            public Result <Command> Handle(Query message)
            {
                var exhibit = _repository.GetExhibit(message.Id);

                if (exhibit == null)
                {
                    return(Result.Fail <Command> ("Exhibit does not exit"));
                }

                var command = new Command
                {
                    Id           = exhibit.Id,
                    Photographer = exhibit.Photographer.Name,
                    Location     = exhibit.Location,
                    Date         = exhibit.DateTime.ToString("d MMM yyyy"),
                    IsCanceled   = exhibit.IsCanceled,
                    ImageUrl     = _urlComposer.ComposeImgUrl(exhibit.ImageUrl)
                };

                return(Result.Ok(command));
            }
Пример #5
0
            public Result Handle(Command message)
            {
                var exhibit = _exhibitRepository.GetExhibit(message.ExhibitId);

                if (exhibit == null)
                {
                    return(Result.Fail <int> ("Exhibit does not exit"));
                }

                var contains = exhibit.Attendances.Any(a => a.AttendeeId == message.UserId);

                if (contains == true)
                {
                    return(Result.Fail <Command> ("Attendance already exists."));
                }

                exhibit.AddAttendance(Attendance.Create(message));
                _exhibitRepository.SaveAll();

                return(Result.Ok());
            }
Пример #6
0
            public Result <Model> Handle(Query message)
            {
                var exhibit = _repository.GetExhibit(message.Id);

                if (exhibit == null)
                {
                    return(Result.Fail <Model> ("Exhibit does not exit"));
                }

                var model = new Model
                {
                    Id           = exhibit.Id,
                    Genre        = exhibit.Genre.Name,
                    Photographer = exhibit.Photographer.Name,
                    Date         = exhibit.DateTime.ToString("d MMM yyyy"),
                    Location     = exhibit.Location,
                    ImageUrl     = _urlComposer.ComposeImgUrl(exhibit.ImageUrl),
                    DateTime     = exhibit.DateTime,
                    IsCanceled   = exhibit.IsCanceled,
                };

                return(Result.Ok(model));
            }