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); }
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); }