Beispiel #1
0
        public EmpleoModuleUpdate(ICommandUpdateIdentity <Empleo> commandUpdate, IFileGetter fileGetter)
        {
            _fileGetter                = fileGetter;
            _empleoMapping             = new EmpleoMapping();
            Put["/enterprise/empleos"] = parameters =>
            {
                var request = this.Bind <EmpleoRequest>();
                if (request.isValidPut())
                {
                    /*    if (request.updateContrato)
                     *  {
                     *      var contrato = request.contrato;
                     *      if (!_fileGetter.existsFile(DirectorioArchivosContratos, contrato, Extension))
                     *      {
                     *          return new Response()
                     *                  .WithStatusCode(HttpStatusCode.BadRequest);
                     *      }
                     *      request.contentFile = fileGetter.getFile(DirectorioArchivosContratos, contrato, Extension);
                     *
                     *  }
                     *  else
                     *  {
                     *      var contrato = request.contrato;
                     *      Guid idContrato;
                     *      if (!Guid.TryParse(contrato, out idContrato)&&!string.IsNullOrEmpty(contrato))
                     *      {
                     *          return new Response()
                     *             .WithStatusCode(HttpStatusCode.BadRequest);
                     *      }
                     *
                     *  }*/
                    var empleo = _empleoMapping.getEmpleoForPut(request);

                    if (commandUpdate.isExecutable(empleo))
                    {
                        commandUpdate.execute(empleo);
                        return(new Response()
                               .WithStatusCode(HttpStatusCode.OK));
                    }
                }

                return(new Response()
                       .WithStatusCode(HttpStatusCode.BadRequest));
            };
        }
Beispiel #2
0
        public EmpleoModuleInsert(ICommandInsertIdentity <Empleo> command, IFileGetter fileGetter)
        {
            _fileGetter    = fileGetter;
            _empleoMapping = new EmpleoMapping();
            Post["/enterprise/empleos"] = parameters =>
            {
                var request = this.Bind <EmpleoRequest>();
                if (request.isValidPost())
                {
                    if (contratoNotEmpty(request))
                    {
                        var contrato = request.contrato;
                        if (!_fileGetter.existsFile(DirectorioArchivosContratos, contrato, Extension))
                        {
                            return(new Response()
                                   .WithStatusCode(HttpStatusCode.BadRequest));
                        }
                        request.contentFile = fileGetter.getFile(@"/EmpleoContratos", contrato, ".pdf");
                    }

                    if (someFileVoucherNotEmpty(request))
                    {
                        if (!existsFilesVoucher(request))
                        {
                            return(new Response()
                                   .WithStatusCode(HttpStatusCode.BadRequest));
                        }

                        setFileContentRequest(request);
                    }


                    var empleo = _empleoMapping.getEmpleoForPost(request);
                    if (command.isExecutable(empleo))
                    {
                        command.execute(empleo);
                        deleteFiles(request);
                        return(new Response()
                               .WithStatusCode(HttpStatusCode.OK));
                    }
                }
                return(new Response()
                       .WithStatusCode(HttpStatusCode.BadRequest));
            };
        }