Example #1
0
        public PartnerDTO GetPartner(int partnerId)
        {
            try
            {
                //Requires.NotNegative("partnerId", partnerId);

                log.Debug("partnerId: " + partnerId + " ");

                // get
                R_Partner t = Repository.GetPartner(partnerId);

                PartnerDTO dto = new PartnerDTO(t);

                log.Debug(PartnerDTO.FormatPartnerDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #2
0
        public int AddPartner(PartnerDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(PartnerDTO.FormatPartnerDTO(dto));

                R_Partner t = PartnerDTO.ConvertDTOtoEntity(dto);

                // add
                id            = Repository.AddPartner(t);
                dto.PartnerId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
Example #3
0
        public void UpdatePartner(R_Partner t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "PartnerId");

            t.Update();
        }
Example #4
0
 public PartnerDTO(R_Partner partner)
 {
     PartnerId             = partner.PartnerId;
     NucleoId              = partner.NucleoId;
     Name                  = partner.Name;
     EnterpriseContributor = partner.EnterpriseContributor;
     PrivateContributor    = partner.PrivateContributor;
     ContributionTypeId    = partner.ContributionTypeId;
     PartnershipTypeId     = partner.PartnershipTypeId;
     ContactPerson         = partner.ContactPerson;
     Department            = partner.Department;
     Phone                 = partner.Phone;
     Email                 = partner.Email;
     Iban                  = partner.Iban;
     BicSwift              = partner.BicSwift;
     FiscalNumber          = partner.FiscalNumber;
     Latitude              = partner.Latitude;
     Longitude             = partner.Longitude;
     PhotoUrl              = partner.PhotoUrl;
     AddressId             = partner.AddressId;
     PartnershipStartDate  = partner.PartnershipStartDate;
     DurationCommitment    = partner.DurationCommitment;
     RefoodAreaInteraction = partner.RefoodAreaInteraction;
     Reliability           = partner.Reliability;
     InteractionFrequency  = partner.InteractionFrequency;
     Active                = partner.Active;
     IsDeleted             = partner.IsDeleted;
     CreateBy              = partner.CreateBy;
     CreateOn              = partner.CreateOn;
     UpdateBy              = partner.UpdateBy;
     UpdateOn              = partner.UpdateOn;
 }
Example #5
0
        public IList <R_Partner> GetPartners(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Partner> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Partner")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                + " or " + "ContactPerson like '%" + searchTerm + "%'"
                + " or " + "Department like '%" + searchTerm + "%'"
                + " or " + "Phone like '%" + searchTerm + "%'"
                + " or " + "Email like '%" + searchTerm + "%'"
                + " or " + "Iban like '%" + searchTerm + "%'"
                + " or " + "BicSwift like '%" + searchTerm + "%'"
                + " or " + "FiscalNumber like '%" + searchTerm + "%'"
                + " or " + "PhotoUrl like '%" + searchTerm + "%'"
                + " or " + "RefoodAreaInteraction like '%" + searchTerm + "%'"
                + " or " + "Reliability like '%" + searchTerm + "%'"
                + " or " + "InteractionFrequency like '%" + searchTerm + "%'"
                )
            ;

            results = R_Partner.Fetch(pageIndex, pageSize, sql);

            return(results);
        }
Example #6
0
        public void GetPartners_Success_Test()
        {
            // Arrange
            R_Partner partner = SamplePartner(1);

            IList <R_Partner> list = new List <R_Partner>();

            list.Add(partner);

            // create mock for repository
            var mock = new Mock <IPartnerRepository>();

            mock.Setup(s => s.GetPartners()).Returns(list);

            // service
            PartnerService partnerService = new PartnerService();

            PartnerService.Repository = mock.Object;

            // Act
            var        resultList = partnerService.GetPartners();
            PartnerDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.PartnerId);
        }
Example #7
0
        public R_Partner GetPartner(int partnerId)
        {
            //Requires.NotNegative("partnerId", partnerId);

            R_Partner t = R_Partner.SingleOrDefault(partnerId);

            return(t);
        }
Example #8
0
        public IEnumerable <R_Partner> GetPartners()
        {
            IEnumerable <R_Partner> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Partner")
                      .Where("IsDeleted = 0")

            ;

            results = R_Partner.Query(sql);

            return(results);
        }
Example #9
0
        public void DeletePartner(PartnerDTO dto)
        {
            try
            {
                log.Debug(PartnerDTO.FormatPartnerDTO(dto));

                R_Partner t = PartnerDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeletePartner(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #10
0
        public void GetPartner_Success_Test()
        {
            // Arrange
            int       id      = 1;
            R_Partner partner = SamplePartner(id);

            // create mock for repository
            var mock = new Mock <IPartnerRepository>();

            mock.Setup(s => s.GetPartner(Moq.It.IsAny <int>())).Returns(partner);

            // service
            PartnerService partnerService = new PartnerService();

            PartnerService.Repository = mock.Object;

            // Act
            PartnerDTO result = partnerService.GetPartner(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.PartnerId);
        }
Example #11
0
        public void UpdatePartner(PartnerDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "PartnerId");

                log.Debug(PartnerDTO.FormatPartnerDTO(dto));

                R_Partner t = PartnerDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdatePartner(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #12
0
        public static R_Partner ConvertDTOtoEntity(PartnerDTO dto)
        {
            R_Partner partner = new R_Partner();

            partner.PartnerId             = dto.PartnerId;
            partner.NucleoId              = dto.NucleoId;
            partner.Name                  = dto.Name;
            partner.EnterpriseContributor = dto.EnterpriseContributor;
            partner.PrivateContributor    = dto.PrivateContributor;
            partner.ContributionTypeId    = dto.ContributionTypeId;
            partner.PartnershipTypeId     = dto.PartnershipTypeId;
            partner.ContactPerson         = dto.ContactPerson;
            partner.Department            = dto.Department;
            partner.Phone                 = dto.Phone;
            partner.Email                 = dto.Email;
            partner.Iban                  = dto.Iban;
            partner.BicSwift              = dto.BicSwift;
            partner.FiscalNumber          = dto.FiscalNumber;
            partner.Latitude              = dto.Latitude;
            partner.Longitude             = dto.Longitude;
            partner.PhotoUrl              = dto.PhotoUrl;
            partner.AddressId             = dto.AddressId;
            partner.PartnershipStartDate  = dto.PartnershipStartDate;
            partner.DurationCommitment    = dto.DurationCommitment;
            partner.RefoodAreaInteraction = dto.RefoodAreaInteraction;
            partner.Reliability           = dto.Reliability;
            partner.InteractionFrequency  = dto.InteractionFrequency;
            partner.Active                = dto.Active;
            partner.IsDeleted             = dto.IsDeleted;
            partner.CreateBy              = dto.CreateBy;
            partner.CreateOn              = dto.CreateOn;
            partner.UpdateBy              = dto.UpdateBy;
            partner.UpdateOn              = dto.UpdateOn;

            return(partner);
        }
Example #13
0
        public IEnumerable <R_Partner> GetPartnerListAdvancedSearch(
            int?nucleoId
            , string name
            , bool?enterpriseContributor
            , bool?privateContributor
            , int?contributionTypeId
            , int?partnershipTypeId
            , string contactPerson
            , string department
            , string phone
            , string email
            , string iban
            , string bicSwift
            , string fiscalNumber
            , double?latitude
            , double?longitude
            , string photoUrl
            , int?addressId
            , System.DateTime?partnershipStartDateFrom
            , System.DateTime?partnershipStartDateTo
            , System.DateTime?durationCommitmentFrom
            , System.DateTime?durationCommitmentTo
            , string refoodAreaInteraction
            , string reliability
            , string interactionFrequency
            , bool?active
            )
        {
            IEnumerable <R_Partner> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Partner")
                      .Where("IsDeleted = 0"
                             + (nucleoId != null ? " and NucleoId like '%" + nucleoId + "%'" : "")
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (enterpriseContributor != null ? " and EnterpriseContributor = " + (enterpriseContributor == true ? "1" : "0") : "")
                             + (privateContributor != null ? " and PrivateContributor = " + (privateContributor == true ? "1" : "0") : "")
                             + (contributionTypeId != null ? " and ContributionTypeId = " + contributionTypeId : "")
                             + (partnershipTypeId != null ? " and PartnershipTypeId = " + partnershipTypeId : "")
                             + (contactPerson != null ? " and ContactPerson like '%" + contactPerson + "%'" : "")
                             + (department != null ? " and Department like '%" + department + "%'" : "")
                             + (phone != null ? " and Phone like '%" + phone + "%'" : "")
                             + (email != null ? " and Email like '%" + email + "%'" : "")
                             + (iban != null ? " and Iban like '%" + iban + "%'" : "")
                             + (bicSwift != null ? " and BicSwift like '%" + bicSwift + "%'" : "")
                             + (fiscalNumber != null ? " and FiscalNumber like '%" + fiscalNumber + "%'" : "")
                             + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "")
                             + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "")
                             + (photoUrl != null ? " and PhotoUrl like '%" + photoUrl + "%'" : "")
                             + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "")
                             + (partnershipStartDateFrom != null ? " and PartnershipStartDate >= '" + partnershipStartDateFrom.Value.ToShortDateString() + "'" : "")
                             + (partnershipStartDateTo != null ? " and PartnershipStartDate <= '" + partnershipStartDateTo.Value.ToShortDateString() + "'" : "")
                             + (durationCommitmentFrom != null ? " and DurationCommitment >= '" + durationCommitmentFrom.Value.ToShortDateString() + "'" : "")
                             + (durationCommitmentTo != null ? " and DurationCommitment <= '" + durationCommitmentTo.Value.ToShortDateString() + "'" : "")
                             + (refoodAreaInteraction != null ? " and RefoodAreaInteraction like '%" + refoodAreaInteraction + "%'" : "")
                             + (reliability != null ? " and Reliability like '%" + reliability + "%'" : "")
                             + (interactionFrequency != null ? " and InteractionFrequency like '%" + interactionFrequency + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Partner.Query(sql);

            return(results);
        }
Example #14
0
 public void DeletePartner(R_Partner t)
 {
     t.IsDeleted = true;
     t.Update();
 }
Example #15
0
        public int AddPartner(R_Partner t)
        {
            int id = (int)t.Insert();

            return(id);
        }
Example #16
0
        // example data

        public static R_Partner SamplePartner(int id = 1)
        {
            R_Partner partner = new R_Partner();

            // int
            partner.PartnerId = id;
            // int?
            partner.NucleoId = 1;
            // string
            partner.Name = "NameTestValue";
            // bool
            partner.EnterpriseContributor = false;
            // bool
            partner.PrivateContributor = false;
            // int
            partner.ContributionTypeId = 1;
            // int
            partner.PartnershipTypeId = 1;
            // string
            partner.ContactPerson = "ContactPersonTestValue";
            // string
            partner.Department = "DepartmentTestValue";
            // string
            partner.Phone = "PhoneTestValue";
            // string
            partner.Email = "EmailTestValue";
            // string
            partner.Iban = "IbanTestValue";
            // string
            partner.BicSwift = "BicSwiftTestValue";
            // string
            partner.FiscalNumber = "FiscalNumberTestValue";
            // double?
            partner.Latitude = 1;
            // double?
            partner.Longitude = 1;
            // string
            partner.PhotoUrl = "PhotoUrlTestValue";
            // int?
            partner.AddressId = 1;
            // System.DateTime?
            partner.PartnershipStartDate = new System.DateTime();
            // System.DateTime?
            partner.DurationCommitment = new System.DateTime();
            // string
            partner.RefoodAreaInteraction = "RefoodAreaInteractionTestValue";
            // string
            partner.Reliability = "ReliabilityTestValue";
            // string
            partner.InteractionFrequency = "InteractionFrequencyTestValue";
            // bool
            partner.Active = false;
            // bool
            partner.IsDeleted = false;
            // int?
            partner.CreateBy = 1;
            // System.DateTime?
            partner.CreateOn = new System.DateTime();
            // int?
            partner.UpdateBy = 1;
            // System.DateTime?
            partner.UpdateOn = new System.DateTime();

            return(partner);
        }