Пример #1
0
        public IEnumerable <LogBdo> GetLastLogs(int offset, int limit)
        {
            var list = new List <LogBdo>();
            IEnumerable <gslog> logs = null;

            try
            {
                using (var db = new GiftServiceEntities())
                {
                    logs = db.gslogs.OrderByDescending(x => x.id)
                           .Skip(offset)
                           .Take(limit)
                           .ToList();
                }

                foreach (var l in logs)
                {
                    list.Add(new LogBdo
                    {
                        Id              = l.id,
                        Message         = l.message,
                        Thread          = l.thread,
                        CreatedAtServer = l.date,
                        Exception       = l.exception,
                        Level           = l.level
                    });
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(list);
        }
Пример #2
0
        public ProductBdo GetProductByUid(string productUid)
        {
            Logger.InfoFormat("Searching product information by UID: `{0}`", productUid);
            ProductBdo product = null;
            product    p       = null;

            try
            {
                using (var db = new GiftServiceEntities())
                {
                    p = db.products.First(x => x.product_uid.Equals(productUid, StringComparison.OrdinalIgnoreCase));
                }

                if (p != null)
                {
                    product = new ProductBdo
                    {
                        Id           = p.id,
                        ProductUid   = p.product_uid,
                        PosUserUid   = p.pos_user_uid,
                        PaySystemUid = p.pay_system_uid,

                        ProductName        = p.product_name,
                        ProductDescription = p.product_description,
                        ProductPrice       = p.product_price,
                        CurrencyCode       = p.currency_code,

                        CustomerName  = p.customer_name,
                        CustomerEmail = p.customer_email,
                        CustomerPhone = p.customer_phone,
                        Remarks       = p.remarks,

                        ValidFrom = p.valid_from.HasValue ? p.valid_from.Value : DateTime.MinValue,
                        ValidTill = p.valid_till.HasValue ? p.valid_till.Value : DateTime.MinValue,

                        PosId      = p.pos_id,
                        PosName    = p.pos_name,
                        PosCity    = p.pos_city,
                        PosAddress = p.pos_address,
                        PosUrl     = p.pos_url,

                        EmailForReservation = p.email_reservation,
                        PhoneForReservation = p.phone_reservation,

                        EmailForGift = p.gift_email,
                        TextForGift  = p.gift_text
                    };
                }

                return(product);
            }
            catch (Exception ex)
            {
                Logger.Error("Error searching product by UID: " + productUid, ex);
                throw;
            }
        }
Пример #3
0
        public TransactionBdo GetTransactionByPaySystemUid(string paySystemUid)
        {
            transaction t = null;

            using (var db = new GiftServiceEntities())
            {
                t = db.transactions.First(x => x.pay_system_uid.Equals(paySystemUid));
            }

            return(MapTo(t));
        }
Пример #4
0
        public TransactionBdo GetTransactionByOrderNr(string orderNr)
        {
            transaction t = null;

            using (var db = new GiftServiceEntities())
            {
                t = db.transactions.First(x => x.order_nr.Equals(orderNr));
            }

            return(MapTo(t));
        }
Пример #5
0
        public string GetUniqueOrderId(int posId)
        {
            Logger.Info("Generating unique order ID (in database)");
            string orderId = null;

            using (var db = new GiftServiceEntities())
            {
                var r = db.unique_orderid_get(posId);
                orderId = r.First();
            }

            return(orderId);
        }
Пример #6
0
        public ProductBdo GetProductByPaySystemUid(string paySystemUid)
        {
            ProductBdo product    = null;
            product    productDao = null;

            Logger.InfoFormat("Searching for product information by payment system UID: `{0}`", paySystemUid);
            using (var db = new GiftServiceEntities())
            {
                productDao = db.products.First(x => paySystemUid.Equals(x.pay_system_uid, StringComparison.OrdinalIgnoreCase));
            }

            if (productDao != null)
            {
                product = new ProductBdo
                {
                    Id           = productDao.id,
                    ProductUid   = productDao.product_uid,
                    PosUserUid   = productDao.pos_user_uid,
                    PaySystemUid = productDao.pay_system_uid,

                    ProductName        = productDao.product_name,
                    ProductDescription = productDao.product_description,
                    ProductDuration    = productDao.product_duration,
                    ProductPrice       = productDao.product_price,
                    CurrencyCode       = productDao.currency_code,

                    CustomerName  = productDao.customer_name,
                    CustomerEmail = productDao.customer_email,
                    CustomerPhone = productDao.customer_phone,
                    Remarks       = productDao.remarks,

                    ValidFrom = productDao.valid_from.HasValue ? productDao.valid_from.Value : DateTime.MinValue,
                    ValidTill = productDao.valid_till.HasValue ? productDao.valid_till.Value : DateTime.MinValue,

                    PosId      = productDao.pos_id,
                    PosName    = productDao.pos_name,
                    PosCity    = productDao.pos_city,
                    PosAddress = productDao.pos_address,
                    PosUrl     = productDao.pos_url,

                    EmailForReservation = productDao.email_reservation,
                    PhoneForReservation = productDao.phone_reservation
                };
            }

            Logger.DebugFormat("  set product duration (from DB) to: `{0}`", product.ProductDuration);
            return(product);
        }
Пример #7
0
        public void Update(TransactionBdo transactionBdo)
        {
            try
            {
                using (var db = new GiftServiceEntities())
                {
                    var t = db.transactions.First(x => x.id == transactionBdo.Id);

                    t.is_payment_processed   = transactionBdo.IsPaymentProcessed;
                    t.is_test_payment        = transactionBdo.IsTestPayment;
                    t.paid_amount            = transactionBdo.PaidAmount;
                    t.paid_currency_code     = transactionBdo.PaidCurrencyCode;
                    t.paid_through           = transactionBdo.PaidThrough;
                    t.payment_status_id      = (int)transactionBdo.PaymentStatus;
                    t.pay_system_id          = (int)transactionBdo.PaymentSystem;
                    t.pay_system_response_at = transactionBdo.PaySystemResponseAt;
                    t.pay_system_uid         = transactionBdo.PaySystemUid;
                    t.pos_id                  = transactionBdo.PosId;
                    t.pos_user_uid            = transactionBdo.PosUserUid;
                    t.product_id              = transactionBdo.ProductId;
                    t.product_uid             = transactionBdo.ProductUid;
                    t.project_id              = transactionBdo.ProjectId.ToString();
                    t.p_email                 = transactionBdo.PayerEmail;
                    t.p_lastname              = transactionBdo.PayerLastName;
                    t.p_name                  = transactionBdo.PayerName;
                    t.p_phone                 = transactionBdo.PayerPhone;
                    t.remarks                 = transactionBdo.Remarks;
                    t.requested_amount        = transactionBdo.RequestedAmount;
                    t.requested_currency_code = transactionBdo.RequestedCurrencyCode;
                    t.response_from_payment   = transactionBdo.ResponseFromPaymentSystem;

                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbvex)
            {
                Logger.Error("Validation error updating transaction", dbvex);
                foreach (var e in dbvex.EntityValidationErrors)
                {
                    foreach (var sub in e.ValidationErrors)
                    {
                        Logger.ErrorFormat("  {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage);
                    }
                }
                throw;
            }
        }
Пример #8
0
        public void MakeProductGift(ProductBdo product, string friendEmail, string text)
        {
            using (var db = new GiftServiceEntities())
            {
                var p = db.products.First(x => x.product_uid == product.ProductUid);
                if (String.IsNullOrEmpty(p.gift_email) == false)
                {
                    // Throw exception if product was sent to other e-mail
                    if (p.gift_email.Equals(friendEmail, StringComparison.OrdinalIgnoreCase) == false)
                    {
                        throw new Models.Exceptions.InvalidProductException(String.Concat("Product was sent to other e-mail: ", p.gift_email), Models.Exceptions.InvalidProductException.Reasons.ProductIsGiftAlready);
                    }
                }

                p.gift_email = friendEmail;
                p.gift_text  = text;

                db.SaveChanges();
            }
        }
Пример #9
0
        public IEnumerable <TransactionBdo> GetLastTransactions(int posId, int offset, int limit)
        {
            Logger.InfoFormat("Getting last transactions for POS ID: #{0}", posId);
            Logger.DebugFormat("  setting offset to:    {0}", offset);
            Logger.DebugFormat("  setting limit to:     {0}", limit);

            var list = new List <TransactionBdo>();

            try
            {
                // TODO: validate offset and limit
                using (var db = new GiftServiceEntities())
                {
                    IQueryable <transaction> ts = db.transactions.OrderByDescending(x => x.id);
                    if (posId > 0)
                    {
                        ts = ts.Where(x => x.pos_id == posId);
                    }
                    ts.Skip(offset).Take(limit);

                    int projectId = 0;
                    PaymentStatusIds paymentStatus = PaymentStatusIds.NotProcessed;
                    PaymentSystems   paymentSystem = PaymentSystems.None;

                    foreach (var t in ts)
                    {
                        int.TryParse(t.project_id, out projectId);
                        Enum.TryParse(t.pay_system_id.ToString(), out paymentSystem);
                        Enum.TryParse(t.payment_status_id.ToString(), out paymentStatus);

                        list.Add(new TransactionBdo
                        {
                            Id = t.id,
                            IsPaymentProcessed = t.is_payment_processed,
                            IsTestPayment      = t.is_test_payment,

                            RequestedAmount       = t.requested_amount,
                            RequestedCurrencyCode = t.requested_currency_code,
                            PaidAmount            = t.paid_amount,
                            PaidCurrencyCode      = t.paid_currency_code,
                            PaidThrough           = t.paid_through,

                            PayerName     = t.p_name,
                            PayerLastName = t.p_lastname,
                            PayerEmail    = t.p_email,
                            PayerPhone    = t.p_phone,
                            Remarks       = t.remarks,

                            ProjectId    = projectId,
                            PosId        = t.pos_id,
                            PosUserUid   = t.pos_user_uid,
                            PaySystemUid = t.pay_system_uid,
                            OrderNr      = t.order_nr,
                            ProductId    = t.product_id,
                            ProductUid   = t.product_uid,

                            PaymentStatus = paymentStatus,
                            PaymentSystem = paymentSystem,

                            CreatedAt           = t.created_at,
                            PaySystemResponseAt = t.pay_system_response_at.HasValue ? t.pay_system_response_at.Value : DateTime.MinValue
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Erro getting last transactions", ex);
                throw;
            }

            return(list);
        }
Пример #10
0
        public void StartTransaction(TransactionBdo t)
        {
            //Mapper.CreateMap<TransactionBdo, transaction>()
            //    .ForMember(dest => dest.payment_status_id,
            //        orig => orig.MapFrom(x => (int)x.PaymentStatus));
            //AutoMapperConfigDal.SetMappingTypeFromBdoToDao();
            //var transaction = Mapper.Map<transaction>(t);
            try
            {
                var transaction = new transaction();
                transaction.is_test_payment         = t.IsTestPayment;
                transaction.payment_status_id       = (int)t.PaymentStatus;
                transaction.is_payment_processed    = t.IsPaymentProcessed;
                transaction.pos_user_uid            = t.PosUserUid;
                transaction.pay_system_uid          = t.PaySystemUid;
                transaction.order_nr                = t.OrderNr;
                transaction.requested_amount        = t.RequestedAmount;
                transaction.requested_currency_code = t.RequestedCurrencyCode;
                transaction.paid_amount             = t.PaidAmount;
                transaction.paid_currency_code      = t.PaidCurrencyCode;
                transaction.paid_through            = t.PaidThrough;
                transaction.p_name      = t.PayerName;
                transaction.p_lastname  = t.PayerLastName;
                transaction.p_email     = t.PayerEmail;
                transaction.p_phone     = t.PayerPhone;
                transaction.remarks     = t.Remarks;
                transaction.pos_id      = t.PosId;
                transaction.product_id  = t.ProductId;
                transaction.product_uid = t.ProductUid;
                transaction.project_id  = t.ProjectId.ToString();
                transaction.created_at  = DateTime.UtcNow;

                Logger.Info("Saving transaction in DB:");
                Logger.DebugFormat("  setting is_test_payment:              `{0}`", transaction.is_test_payment);
                Logger.DebugFormat("  setting payment_status_id:            `{0}`", transaction.payment_status_id);
                Logger.DebugFormat("  setting is_payment_processed:         `{0}`", transaction.is_payment_processed);
                Logger.DebugFormat("  setting pos_user_uid:                 `{0}`", transaction.pos_user_uid);
                Logger.DebugFormat("  setting pay_system_uid:               `{0}`", transaction.pay_system_uid);
                Logger.DebugFormat("  setting order_nr:                     `{0}`", transaction.order_nr);

                Logger.DebugFormat("  setting requested_amount:             `{0}`", transaction.requested_amount);
                Logger.DebugFormat("  setting requested_currency_code:      `{0}`", transaction.requested_currency_code);
                Logger.DebugFormat("  setting paid_amount:                  `{0}`", transaction.paid_amount);
                Logger.DebugFormat("  setting paid_currency_code:           `{0}`", transaction.paid_currency_code);
                Logger.DebugFormat("  setting paid_through:                 `{0}`", transaction.paid_through);

                Logger.DebugFormat("  setting p_name:                       `{0}`", transaction.p_name);
                Logger.DebugFormat("  setting p_lastname:                   `{0}`", transaction.p_lastname);
                Logger.DebugFormat("  setting p_email:                      `{0}`", transaction.p_email);
                Logger.DebugFormat("  setting p_phone:                      `{0}`", transaction.p_phone);
                Logger.DebugFormat("  setting remarks:                      `{0}`", transaction.remarks);

                Logger.DebugFormat("  setting pos_id:                       `{0}`", transaction.pos_id);
                Logger.DebugFormat("  setting product_id:                   `{0}`", transaction.product_id);
                Logger.DebugFormat("  setting product_uid:                  `{0}`", transaction.product_uid);

                Logger.DebugFormat("  setting response_from_payment:        `{0}`", transaction.response_from_payment);
                Logger.DebugFormat("  setting pay_system_response_at:       `{0}`", transaction.pay_system_response_at);
                Logger.DebugFormat("  setting created_at:                   `{0}`", transaction.created_at);

                using (var db = new GiftServiceEntities())
                {
                    db.transactions.Add(transaction);
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbvex)
            {
                Logger.Error("Validation error saving transaction", dbvex);
                foreach (var e in dbvex.EntityValidationErrors)
                {
                    foreach (var sub in e.ValidationErrors)
                    {
                        Logger.ErrorFormat("  {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage);
                    }
                }
                throw;
            }
        }
Пример #11
0
        public ProductBdo SaveProductInformationFromPos(ProductBdo product, PosBdo pos)
        {
            var p = new product();

            try
            {
                //AutoMapperConfigDal.SetMappingTypeFromBdoToDao();
                //p = Mapper.Map<product>(product);

                p.pos_user_uid   = product.PosUserUid;
                p.pay_system_uid = product.PaySystemUid;

                p.product_uid         = product.ProductUid;
                p.product_name        = product.ProductName;
                p.product_description = product.ProductDescription;
                p.product_duration    = product.ProductDuration;
                Logger.DebugFormat("  setting product_duration to: `{0}`", p.product_duration);
                p.product_price = product.ProductPrice;
                p.currency_code = product.CurrencyCode;

                p.customer_name  = product.CustomerName;
                p.customer_phone = product.CustomerPhone;
                p.customer_email = product.CustomerEmail;
                p.remarks        = product.Remarks;

                p.email_reservation = product.EmailForReservation;
                p.phone_reservation = product.PhoneForReservation;

                p.pos_id      = product.PosId;
                p.pos_name    = product.PosName;
                p.pos_address = product.PosAddress;
                p.pos_city    = product.PosCity;

                p.valid_from = product.ValidFrom;
                p.valid_till = product.ValidTill;

                Logger.Info("Saving product:");
                Logger.DebugFormat("  pos_user_uid:          `{0}`", p.pos_user_uid);
                Logger.DebugFormat("  pay_system_uid:        `{0}`", p.pay_system_uid);

                Logger.DebugFormat("  product_uid:           `{0}`", p.product_uid);
                Logger.DebugFormat("  product_name:          `{0}`", p.product_name);
                Logger.DebugFormat("  product_description:   `{0}`", p.product_description);
                Logger.DebugFormat("  product_duration:      `{0}`", p.product_duration);
                Logger.DebugFormat("  product_price:         `{0}`", p.product_price);
                Logger.DebugFormat("  currency_code:         `{0}`", p.currency_code);

                Logger.DebugFormat("  customer_name:         `{0}`", p.customer_name);
                Logger.DebugFormat("  customer_phone:        `{0}`", p.customer_phone);
                Logger.DebugFormat("  customer_email:        `{0}`", p.customer_email);
                Logger.DebugFormat("  remarks:               `{0}`", p.remarks);

                Logger.DebugFormat("  email_reservation:     `{0}`", p.email_reservation);
                Logger.DebugFormat("  phone_reservation:     `{0}`", p.phone_reservation);

                Logger.DebugFormat("  pos_id:                `{0}`", p.pos_id);
                Logger.DebugFormat("  pos_name:              `{0}`", p.pos_name);
                Logger.DebugFormat("  pos_city:              `{0}`", p.pos_city);
                Logger.DebugFormat("  pos_address:           `{0}`", p.pos_address);
                Logger.DebugFormat("  valid_from:            `{0}`", p.valid_from);
                Logger.DebugFormat("  valid_till:            `{0}`", p.valid_till);
                //Logger.DebugFormat("  PaymentSystem:        `{0}`", p.Pay);
                using (var db = new GiftServiceEntities())
                {
                    db.products.Add(p);
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbvex)
            {
                Logger.Error("Validation error saving product", dbvex);
                foreach (var e in dbvex.EntityValidationErrors)
                {
                    foreach (var sub in e.ValidationErrors)
                    {
                        Logger.ErrorFormat("  {0,-16}: {1}", sub.PropertyName, sub.ErrorMessage);
                    }
                }
                throw;
            }

            return(product);
        }