public async Task <IHttpActionResult> GetParameters()
        {
            var result = await Task.Run(() =>
            {
                return(ParameterFacade.GetParameters());
            });

            return(this.Ok(result));
        }
예제 #2
0
        public static CustomerDto NewCustomer(string nickName, string fullName, string facebook,
                                              string phone, DateTime birthDate, string address, float firstTimeAmount)
        {
            using (JiewStoreEntities context = new JiewStoreEntities())
            {
                float pointPerAmount = ParameterFacade.GetPointPerAmount(context);
                float pointMultipler = BirthMonthBonusPointCondition.GetMultipler(birthDate);;

                IPointCalculator pointCalculator = new JiewPointCalculator(pointPerAmount, pointMultipler);

                Customer newCustomer = CustomerHelper.NewCustomer(nickName,
                                                                  fullName,
                                                                  facebook,
                                                                  phone,
                                                                  birthDate,
                                                                  address);

                Transaction newTransaction = TransactionHelper.MakeNewAmountTransaction(newCustomer,
                                                                                        firstTimeAmount,
                                                                                        pointPerAmount,
                                                                                        pointMultipler,
                                                                                        "new customer",
                                                                                        pointCalculator);

                try
                {
                    context.Customers.Add(newCustomer);
                    context.Transactions.Add(newTransaction);
                    context.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }

                return(AutoMapper.Mapper.Map <CustomerDto>(newCustomer));
            } //using (JiewStoreEntities context = new JiewStoreEntities())
        }