示例#1
0
 public CreatedDisaster Map(Disaster disaster)
 {
     return new CreatedDisaster()
         {
             Id = disaster.Id
         };
 }
示例#2
0
        public void Handle(IUserSession userSessionIssuingCommand, object command)
        {
            var c = (CreateNewDisaster) command;
            var u = (UserSession) userSessionIssuingCommand;

            var itemToCreate = new Disaster(_timeProvider.Now(), c.LocationDescription, c.Latitude, c.Longitude);
            itemToCreate.AddSeverityVote(u.User, c.FirstSeverity);

            Disaster newDisaster = _writeableRepository.Create(itemToCreate);
            NotifyObservers(new NewDisasterCreated(u.User.Id,newDisaster.Id, newDisaster.CreatedDate, c.LocationDescription,
                                                   c.Latitude, c.Longitude, c.FirstSeverity));
        }
        public void Handle(IUserSession userSessionIssuingCommand, object command)
        {

            var c = (CreateNewDisaster) command;
            var u = (UserSession)userSessionIssuingCommand;

            var itemToCreate = new Disaster(c.CreatedDate, c.LocationDescription, c.Latitude, c.Longitude);

            var newDisasterImage = itemToCreate.AddImage(c.FirstImageUrl);
            var newSeverityVote = itemToCreate.AddSeverityVote(u.User, c.FirsSeverity);
            var newDisaster = _writeableRepository.Create(itemToCreate);

            NotifyObservers(new NewDisasterCreated(newDisaster.Id, newDisaster.CreatedDate, c.LocationDescription, c.Latitude, c.Longitude, c.FirstImageUrl,c.FirsSeverity));

        }
示例#4
0
        public DisasterModule(ICommandDispatcher commandDispatcher)
        {
            Post["/Disasters"] =
                Request =>
                    {
                        var req = this.Bind<CreateNewDisasterRequest>();
                        commandDispatcher.Dispatch(this.UserSession(),
                                                   new CreateNewDisaster(req.LocationDescription,
                                                                         req.Latitude, req.Longitude, req.FirstSeverity));
                        return new Response().WithStatusCode(HttpStatusCode.OK);
                    };

            Post["/SendDisasterByEmail"] =
                Request =>
                    {
                        var emailInfo = this.Bind<SendDisasterByEmailRequest>();
                        try
                        {
                            var _model = new Disaster(DateTime.Parse(emailInfo.CreatedDate),
                                                      emailInfo.LocationDescription,
                                                      double.Parse(emailInfo.Latitude),
                                                      double.Parse(emailInfo.Longitude));
                            var sender =
                                new EmailSender(
                                    new EmailBodyRenderer(
                                        new TemplateProvider(new List<IEmailTemplate>
                                                                 {
                                                                     new DisasterEmailTemplate(
                                                                         new DefaultRootPathProvider())
                                                                 }),
                                        new DefaultViewEngine())
                                    , new EmailSubjectProvider(new List<IEmailSubject> {new DisasterEmailSubject()}),
                                    new MailgunSmtpClient());
                            sender.Send(_model, emailInfo.Email);
                            return new Response().WithStatusCode(HttpStatusCode.OK);
                        }
                        catch (Exception ex)
                        {
                            return new Response().WithStatusCode(HttpStatusCode.NotFound);
                        }
                    };
        }