Ejemplo n.º 1
0
        public async Task <ActionResult> Save(CodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CodeViewModel();
                return(View("CodeForm", viewModel));
            }

            if (model.Id == 0)
            {
                var codeDB = new Codes();
                codeDB.PinCode = model.Code;
                await dataservice.AddCodeAsync(codeDB);
            }
            else
            {
                var codeInDb = await dataservice.GetCodeAsync(model.Id);

                codeInDb.PinCode = model.Code;
                await dataservice.UpdateCodeAsync(codeInDb);
            }
            return(RedirectToAction("Index", "Code"));
        }