예제 #1
0
        public async Task <IWriterResult> CreateLottoItem(CreateLottoItemModel model)
        {
            using (var context = ExchangeDataContextFactory.CreateContext())
            {
                var lottoItem = new LottoItem
                {
                    Name          = model.Name,
                    CurrencyId    = model.CurrencyId,
                    CurrentDrawId = 1,
                    Description   = model.Description,
                    Fee           = model.Fee,
                    Hours         = model.Hours,
                    LottoType     = model.LottoType,
                    Prizes        = model.Prizes,
                    Rate          = model.Rate,
                    NextDraw      = model.NextDraw,
                    Status        = model.Status,
                    Expires       = model.Expires
                };
                context.LottoItem.Add(lottoItem);
                await context.SaveChangesAsync().ConfigureAwait(false);

                return(new WriterResult(true, "Successfully created lotto item."));
            }
        }
        public async Task <ActionResult> CreateLottoItem(CreateLottoItemModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Currencies = await CurrencyReader.GetCurrencies();

                return(View("CreateLottoItemModal", model));
            }

            var result = await LottoWriter.CreateLottoItem(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("CreateLottoItemModal", model));
            }

            return(CloseModalSuccess(result.Message));
        }