コード例 #1
0
        public OperationResult <SellerDTO> Create(SellerDTO seller)
        {
            var validation = ValidateEntity(seller);

            if (validation != OK)
            {
                return(new OperationResult <SellerDTO>(validation, Logger.LogEvent(validation)));
            }
            try
            {
                var rol = new InfoSellers.Repository.RolRepository().ReadById(seller.RolID);
                if (rol == null)
                {
                    return(new OperationResult <SellerDTO>("Specified rol was not found", Logger.LogEvent(validation)));
                }
                var commissionType = new CommissionTypeRepository().ReadById(rol.CommissionTypeID);

                var repository = new InfoSellers.Repository.SellerRepository();

                seller.CurrentCommission = commissionType.CommissionValue;

                var encryptedNIT = SecurityHelper.EncryptString(ENCRYPTION_KEY, seller.Nit);
                seller.Nit = encryptedNIT;
                var newSeller = repository.Create(seller);
                return(new OperationResult <SellerDTO>(seller));
            }
            catch (Exception ex)
            {
                return(new OperationResult <SellerDTO>("Error creating the seller", Logger.LogEvent(ex.Message)));
            }
        }
コード例 #2
0
        public OperationResult <SellerDTO> Update(SellerDTO seller)
        {
            var validation = ValidateEntity(seller);

            if (validation != OK)
            {
                return(new OperationResult <SellerDTO>(validation, Logger.LogEvent(validation)));
            }
            if (seller.ID <= 0)
            {
                return(new OperationResult <SellerDTO>("Invalid ID", Logger.LogEvent(validation)));
            }
            try
            {
                var repository = new InfoSellers.Repository.SellerRepository();
                var dbSeller   = repository.ReadById(seller.ID);
                if (dbSeller == null)
                {
                    return(new OperationResult <SellerDTO>("ID specified was not found", Logger.LogEvent(validation)));
                }
                seller.PenaltyPercentage = dbSeller.PenaltyPercentage; //This value cannot change
                var rol = new InfoSellers.Repository.RolRepository().ReadById(seller.RolID);
                if (rol == null)
                {
                    return(new OperationResult <SellerDTO>("Specified rol was not found", Logger.LogEvent(validation)));
                }
                var commissionType = new CommissionTypeRepository().ReadById(rol.CommissionTypeID);
                seller.CurrentCommission = commissionType.CommissionValue;
                if (seller.Active != dbSeller.Active)
                {
                    if (!seller.Active) //Deactivating seller...
                    {
                        seller.CurrentCommission = commissionType.CommissionValue - (commissionType.CommissionValue * (dbSeller.PenaltyPercentage / 100));
                    }
                }

                var encryptedNIT = SecurityHelper.EncryptString(ENCRYPTION_KEY, seller.Nit);
                seller.Nit = encryptedNIT;

                var updatedSeller = repository.Update(seller);
                return(new OperationResult <SellerDTO>(updatedSeller));
            }
            catch (Exception ex)
            {
                return(new OperationResult <SellerDTO>("Error updating the seller", Logger.LogEvent(ex.Message)));
            }
        }