public async Task <ActionResult> UpdateLottoItem(UpdateLottoItemModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UpdateLottoItemModal", model));
            }

            var result = await LottoWriter.UpdateLottoItem(model);

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

            return(CloseModalSuccess(result.Message));
        }
Ejemplo n.º 2
0
        public async Task <IWriterResult> UpdateLottoItem(UpdateLottoItemModel model)
        {
            using (var context = ExchangeDataContextFactory.CreateContext())
            {
                var lottoItem =
                    await context.LottoItem.Where(x => x.Id == model.LottoItemId).FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                if (lottoItem == null)
                {
                    return(new WriterResult(false, "LottoItem #{0} not found", model.LottoItemId));
                }

                lottoItem.Name        = model.Name;
                lottoItem.Description = model.Description;
                lottoItem.LottoType   = model.LottoType;
                lottoItem.Status      = model.Status;
                await context.SaveChangesAsync().ConfigureAwait(false);

                return(new WriterResult(true, "Successfully updated lotto item."));
            }
        }