Beispiel #1
0
        private IHttpActionResult GetDonorForUnauthenticatedUser(string email)
        {
            try
            {
                var donor = _donorService.GetContactDonorForEmail(email);
                if (donor == null || !donor.HasPaymentProcessorRecord)
                {
                    return(NotFound());
                }
                else
                {
                    var response = new DonorDTO
                    {
                        Id             = donor.DonorId,
                        ProcessorId    = donor.ProcessorId,
                        RegisteredUser = donor.RegisteredUser,
                        Email          = donor.Email
                    };

                    return(Ok(response));
                }
            }
            catch (PaymentProcessorException stripeException)
            {
                return(stripeException.GetStripeResult());
            }
            catch (Exception exception)
            {
                var apiError = new ApiErrorDto("Donor Get Failed", exception);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
        }
Beispiel #2
0
        private IHttpActionResult CreateDonorForAuthenticatedUser(string authToken, CreateDonorDTO dto)
        {
            try
            {
                var donor = _donorService.GetContactDonorForAuthenticatedUser(authToken);
                donor = _donorService.CreateOrUpdateContactDonor(donor, string.Empty, string.Empty, string.Empty, string.Empty, dto.stripe_token_id, DateTime.Now);

                var response = new DonorDTO
                {
                    Id             = donor.DonorId,
                    ProcessorId    = donor.ProcessorId,
                    RegisteredUser = true,
                    Email          = donor.Email
                };

                return(Ok(response));
            }
            catch (PaymentProcessorException e)
            {
                return(e.GetStripeResult());
            }
            catch (Exception exception)
            {
                var apiError = new ApiErrorDto("Donor Post Failed", exception);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
        }
Beispiel #3
0
 public DonorBM(DonorDTO donorDto, AddressBM addressBm = null, OrganizationBM organizationBm = null) : base(donorDto, addressBm)
 {
     this.address        = addressBm;
     this.donorId        = donorDto.donorId;
     this.organization   = organizationBm;
     this.canBeContacted = donorDto.canBeContacted;
 }
        public bool UpdateDonor(DonorDTO donorDTO)
        {
            using (var context = new BankaContext())
            {
                Donor noviDonor  = new Donor(donorDTO);
                Donor stariDonor = null;
                foreach (var item in context.Donori)
                {
                    if (item.Id.Equals(donorDTO.Id))
                    {
                        stariDonor = item;
                        break;
                    }
                }
                if (stariDonor != null)
                {
                    stariDonor = noviDonor;
                }



                context.SaveChanges();
            }
            return(true);
        }
        public DonorDTO DeleteDonor(DonorDTO donorDTO)
        {
            // throw new NotImplementedException();
            Donor retVal = null;

            using (var context = new BankaContext())
            {
                foreach (var item in context.Donori)
                {
                    if (item.Id.Equals(donorDTO.Id))
                    {
                        retVal = item;
                        break;
                    }
                }
                if (retVal == null)
                {
                    return(null);
                }



                context.Donori.Remove(retVal);
                context.SaveChanges();
            }

            return(new DonorDTO(retVal.Id, retVal.Ime, retVal.KrvnaGrupa, retVal.Prezime));
        }
Beispiel #6
0
        public ResultBM GetDonor(int donorId)
        {
            try
            {
                AddressBLL      addressBll         = new AddressBLL();
                ResultBM        addressResult      = null;
                OrganizationBLL organizationBll    = new OrganizationBLL();
                OrganizationBM  organizationBm     = null;
                ResultBM        resultOrganization = null;
                DonorDAL        donorDal           = new DonorDAL();
                DonorBM         donorBm            = null;

                DonorDTO donorDto = donorDal.GetDonor(donorId);

                // Si el donador existe, deb existir la persona
                if (donorDto != null)
                {
                    addressResult = addressBll.GetAddress(donorDto.addressId);

                    //Si hubo algún problema o la dirección no existe, entonces hay que devolver el resultado o lanzar una excepción (debería eixstir)
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " addressId " + donorDto.addressId);
                    }

                    // Podría no pertenecer a una organización, de modo tal que si no posee relación, está bien
                    if (donorDto.organizationId != 0)
                    {
                        resultOrganization = organizationBll.GetOrganization(donorDto.organizationId);

                        if (!resultOrganization.IsValid())
                        {
                            return(resultOrganization);
                        }
                        if (resultOrganization.GetValue() == null)
                        {
                            throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " organizationId " + donorDto.organizationId);
                        }

                        organizationBm = resultOrganization.GetValue <OrganizationBM>();
                    }

                    donorBm = new DonorBM(donorDto, addressResult.GetValue <AddressBM>(), organizationBm);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", donorBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #7
0
        private IHttpActionResult UpdateDonor(string token, UpdateDonorDTO dto)
        {
            MpContactDonor mpContactDonor;
            SourceData     sourceData;

            try
            {
                mpContactDonor =
                    token == null?
                    _donorService.GetContactDonorForEmail(dto.EmailAddress)
                        :
                        _donorService.GetContactDonorForAuthenticatedUser(token);

                sourceData = _stripePaymentService.UpdateCustomerSource(mpContactDonor.ProcessorId, dto.StripeTokenId);
            }
            catch (PaymentProcessorException stripeException)
            {
                return(stripeException.GetStripeResult());
            }
            catch (ApplicationException applicationException)
            {
                var apiError = new ApiErrorDto("Error calling Ministry Platform" + applicationException.Message, applicationException);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }

            //return donor
            var donor = new DonorDTO
            {
                Id            = mpContactDonor.DonorId,
                ProcessorId   = mpContactDonor.ProcessorId,
                DefaultSource = new DefaultSourceDTO
                {
                    credit_card = new CreditCardDTO
                    {
                        brand       = sourceData.brand,
                        last4       = sourceData.last4,
                        address_zip = sourceData.address_zip,
                        exp_date    = sourceData.exp_month + sourceData.exp_year
                    },
                    bank_account = new BankAccountDTO
                    {
                        last4             = sourceData.bank_last4,
                        routing           = sourceData.routing_number,
                        accountHolderName = sourceData.account_holder_name,
                        accountHolderType = sourceData.account_holder_type
                    }
                },
                RegisteredUser = mpContactDonor.RegisteredUser,
                Email          = mpContactDonor.Email
            };

            return(Ok(donor));
        }
Beispiel #8
0
        private IHttpActionResult CreateDonorForUnauthenticatedUser(CreateDonorDTO dto)
        {
            MpContactDonor donor;

            try
            {
                donor = _donorService.GetContactDonorForEmail(dto.email_address);
            }
            catch (Exception e)
            {
                var msg = "Error getting donor for email " + dto.email_address;
                logger.Error(msg, e);
                var apiError = new ApiErrorDto(msg, e);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
            int existingDonorId =
                (donor == null) ?
                0 :
                donor.DonorId;

            try
            {
                donor = _donorService.CreateOrUpdateContactDonor(donor, String.Empty, dto.first_name, dto.last_name, dto.email_address, dto.stripe_token_id, DateTime.Now);
            }
            catch (PaymentProcessorException e)
            {
                return(e.GetStripeResult());
            }
            catch (Exception e)
            {
                var msg = "Error creating donor for email " + dto.email_address;
                logger.Error(msg, e);
                var apiError = new ApiErrorDto(msg, e);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }

            var responseBody = new DonorDTO
            {
                Id             = donor.DonorId,
                ProcessorId    = donor.ProcessorId,
                RegisteredUser = false,
                Email          = donor.Email
            };

            // HTTP StatusCode should be 201 (Created) if we created a donor, or 200 (Ok) if returning an existing donor
            var statusCode =
                (existingDonorId == donor.DonorId) ?
                HttpStatusCode.OK :
                HttpStatusCode.Created;

            return(ResponseMessage(Request.CreateResponse(statusCode, responseBody)));
        }
Beispiel #9
0
        private IHttpActionResult GetDonorForAuthenticatedUser(string token)
        {
            try
            {
                var donor = _donorService.GetContactDonorForAuthenticatedUser(token);

                if (donor == null || !donor.HasPaymentProcessorRecord)
                {
                    return(NotFound());
                }
                else
                {
                    var defaultSource = _stripePaymentService.GetDefaultSource(donor.ProcessorId);

                    var response = new DonorDTO()
                    {
                        Id            = donor.DonorId,
                        ProcessorId   = donor.ProcessorId,
                        DefaultSource = new DefaultSourceDTO
                        {
                            credit_card = new CreditCardDTO
                            {
                                last4       = defaultSource.last4,
                                brand       = defaultSource.brand,
                                address_zip = defaultSource.address_zip,
                                exp_date    = defaultSource.exp_month + defaultSource.exp_year
                            },
                            bank_account = new BankAccountDTO
                            {
                                last4             = defaultSource.bank_last4,
                                routing           = defaultSource.routing_number,
                                accountHolderName = defaultSource.account_holder_name,
                                accountHolderType = defaultSource.account_holder_type
                            }
                        },
                        RegisteredUser = donor.RegisteredUser,
                        Email          = donor.Email
                    };

                    return(Ok(response));
                }
            }
            catch (PaymentProcessorException stripeException)
            {
                return(stripeException.GetStripeResult());
            }
            catch (Exception exception)
            {
                var apiError = new ApiErrorDto("Donor Get Failed", exception);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }
        }
Beispiel #10
0
        public bool UpdateDonor(DonorDTO donorDto)
        {
            DBSql  dbsql = new DBSql();
            String sql;

            sql  = "UPDATE donor SET ";
            sql += "personId = " + donorDto.id + ", ";
            sql += "organizationId = " + (donorDto.organizationId == 0 ? "null" : donorDto.organizationId.ToString()) + ", ";
            sql += "canBeContacted = '" + donorDto.canBeContacted + "' ";
            sql += "WHERE id = " + donorDto.donorId;
            dbsql.ExecuteNonQuery(sql);
            return(true);
        }
Beispiel #11
0
        public bool SaveDonor(DonorDTO donorDto)
        {
            DBSql  dbsql = new DBSql();
            String sql;

            sql  = "INSERT INTO donor (personId, organizationId, canBeContacted) VALUES (";
            sql += donorDto.id + ", ";
            sql += donorDto.organizationId == 0 ? "null, " : donorDto.organizationId + ", ";
            sql += "'" + donorDto.canBeContacted + "'";
            sql += ");SELECT @@IDENTITY";
            donorDto.donorId = dbsql.ExecuteNonQuery(sql);
            return(true);
        }
Beispiel #12
0
        /// <summary>
        /// Crea un nuevo donador.
        /// </summary>
        /// <param name="donorBm"></param>
        /// <returns></returns>
        public ResultBM SaveDonor(DonorBM donorBm)
        {
            try
            {
                OrganizationBLL organizationBll    = new OrganizationBLL();
                ResultBM        resultOrganization = null;
                OrganizationBM  organizationBm     = null;
                DonorDAL        donorDal           = new DonorDAL();
                PersonBLL       personBll          = new PersonBLL();
                PersonBM        personBm           = null;
                ResultBM        validationResult;
                ResultBM        personResult;
                DonorDTO        donorDto;

                // El validador no es necesario porque el donador es una combinación de otras entidades que ya poseen validadores.
                validationResult = IsValid(donorBm);
                if (!validationResult.IsValid())
                {
                    return(validationResult);
                }

                personResult = personBll.SavePerson(donorBm);
                if (!personResult.IsValid())
                {
                    return(personResult);
                }

                if (donorBm.organization != null)
                {
                    resultOrganization = organizationBll.SaveOrganization(donorBm.organization);
                    if (!resultOrganization.IsValid())
                    {
                        return(resultOrganization);
                    }
                    //if (resultOrganization.GetValue() == null) return new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("SAVING_ERROR"), resultOrganization);

                    organizationBm = resultOrganization.GetValue <OrganizationBM>();
                }

                personBm = personResult.GetValue() as PersonBM;
                donorDto = new DonorDTO(personBm.id, donorBm.donorId, organizationBm == null ? 0 : organizationBm.id, donorBm.CanBeContacted);
                donorDal.SaveDonor(donorDto);
                donorBm.donorId = donorDto.donorId;

                return(new ResultBM(ResultBM.Type.OK, "Se ha creado el donador " + donorBm.name + " " + donorBm.lastName + ".", donorBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("SAVING_ERROR") + " " + exception.Message, exception));
            }
        }
        public DonorDTO CreateDonor(DonorDTO donorDTO)
        {
            Donor retVal = null;

            using (var context = new BankaContext()) //citava baza mi je u prom context sada
            {
                retVal = new Donor(donorDTO);
                context.Donori.Add(retVal);
                context.SaveChanges();
            }
            if (retVal == null)
            {
                return(null);
            }
            return(new DonorDTO(retVal.Id, retVal.Ime, retVal.KrvnaGrupa, retVal.Prezime));
        }
        public List <DonorDTO> ReadByFilterDonor(DonorDTO donorDTO)
        {
            // throw new NotImplementedException();
            List <DonorDTO> povratna = new List <DonorDTO>();

            using (var context = new BankaContext())
            {
                foreach (var item in context.Donori)
                {
                    if (item.MatchesFilter(donorDTO))
                    {
                        povratna.Add(new DonorDTO(item.Id, item.Ime, item.KrvnaGrupa, item.Prezime));
                    }
                }
            }
            return(povratna);
        }
Beispiel #15
0
        private DonorDTO Resolve(List <String> item)
        {
            DonorDTO result = new DonorDTO();

            result.id             = int.Parse(item[0]);
            result.name           = item[1];
            result.lastName       = item[2];
            result.birthdate      = DateTime.Parse(item[3]);
            result.email          = item[4];
            result.phone          = item[5];
            result.gender         = Char.Parse(item[6]);
            result.dni            = int.Parse(item[7]);
            result.addressId      = int.Parse(item[8]);
            result.donorId        = int.Parse(item[9]);
            result.organizationId = int.Parse(item[10] == "" ? "0" : item[10]);
            result.canBeContacted = bool.Parse(item[11]);
            return(result);
        }
Beispiel #16
0
        //No está bueno esto, pero me permite recuperar las direcciones. Poco performante... pero no hay tiempo.
        private AddressBM GetAddress(DonorDTO donorDto)
        {
            ResultBM addressResult = new AddressBLL().GetAddress(donorDto.addressId);

            return(addressResult.GetValue <AddressBM>());
        }