Esempio n. 1
0
        public bool RedeemPrizeEF(int prizeID)
        {
            bool res = false;

            try
            {
                using (var ctx = new wpnDBEntities1())
                {
                    PromosWPN updatingPrize = ctx.PromosWPNs.Where(s => s.PrizeID == prizeID).SingleOrDefault();

                    if (updatingPrize != null)
                    {
                        if (updatingPrize.IsRedeemed == true)//was already redeemed
                        {
                            throw new Exception(Constants.ALREADY_REDEEMED_CODE);
                            //return true;
                        }

                        updatingPrize.RedeemedDate = DateTime.Now;
                        updatingPrize.IsRedeemed   = true;

                        ctx.SaveChanges();

                        res = true; //all ok
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(res);
        }
Esempio n. 2
0
        public bool InsertCustomerInformationEF(Customer customer, IEnumerable <PromoSpPrize> promoPrizePool)
        {
            bool             res       = false;
            List <PromosWPN> promosWPN = new List <PromosWPN>();

            //handle prizePool
            foreach (var promo in promoPrizePool)
            {
                promosWPN.Add(new PromosWPN()
                {
                    //PrizeID = promo.PrizeID,
                    IsRedeemed     = promo.IsRedeemed,
                    CustomerID     = customer.CustomerID,
                    ActivationDate = promo.ActivationDate,
                    ExpirationDate = promo.ExpirationDate,
                    PrizeAmount    = promo.PrizeAmount,
                    RedeemedDate   = promo.RedeemedDate,
                });
            }


            try
            {
                using (var ctx = new wpnDBEntities1())
                {
                    ctx.CustomersWPNs.Add(new CustomersWPN()
                    {
                        FirstName      = customer.FirstName,
                        LastName       = customer.LastName,
                        CustomerNumber = customer.CustomerNumber
                    });

                    ctx.PromosWPNs.AddRange(promosWPN);

                    ctx.SaveChanges();

                    res = true; // all went ok
                }
            }
            catch (Exception ex)
            {
                //res = false;
            }

            return(res);
        }
Esempio n. 3
0
        public bool CheckCustomerExistsEF(Customer customer)
        {
            bool res = true;// cu exists

            using (var ctx = new wpnDBEntities1())
            {
                var matchingCustomers = ctx.CustomersWPNs.Where(s => (s.FirstName.Equals(customer.FirstName) &&
                                                                      s.LastName.Equals(customer.LastName)) ||
                                                                (s.CustomerID == customer.CustomerID &&
                                                                 s.CustomerID > 0)     //customerID=0 is invalid
                                                                ).FirstOrDefault();
                if (matchingCustomers == null)
                {
                    res = false; // no cu exists
                }
            }

            return(res);
        }
Esempio n. 4
0
        public IEnumerable <PromoSpPrize> GetAllCustomerPromosEF(Customer customer)
        {
            IList <PromoSpPrize> customerPromoPool = null;

            try
            {
                using (var ctx = new wpnDBEntities1())
                {
                    if (customer.CustomerID < 1)//invalid custID, since it isnt int? it cannot be null, 0 by default
                    {
                        customer.CustomerID = ctx.CustomersWPNs
                                              .Where(s => s.FirstName.Equals(customer.FirstName) && s.LastName.Equals(customer.LastName))
                                              .Select(s => s.CustomerID)
                                              .Single();  //throws an exeption if not a single element
                    }

                    customerPromoPool = ctx.PromosWPNs
                                        .Where(s => s.CustomerID == customer.CustomerID)
                                        .Select(s => new PromoSpPrize()
                    {
                        PrizeID        = s.PrizeID,
                        PrizeAmount    = (decimal)s.PrizeAmount,
                        IsRedeemed     = (bool)s.IsRedeemed,
                        ActivationDate = (DateTime)s.ActivationDate,
                        ExpirationDate = s.ExpirationDate,
                        RedeemedDate   = s.RedeemedDate
                    })
                                        .ToList <PromoSpPrize>();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(customerPromoPool);
        }