예제 #1
0
        public async Task <IActionResult> Upsert(PatrimoniosVM obj)
        {
            if (ModelState.IsValid)
            {
                if (obj.Patrimonio.Id == 0)
                {
                    obj.Patrimonio.Created     = DateTime.Now;
                    obj.Patrimonio.NumeroTombo = new Random().Next();
                    await _npPatrimonio.CreateAsync(SD.PatrimonioAPIPath, obj.Patrimonio, HttpContext.Session.GetString("JWToken"));
                }
                else
                {
                    await _npPatrimonio.UpdateAsync(SD.PatrimonioAPIPath + obj.Patrimonio.Id, obj.Patrimonio, HttpContext.Session.GetString("JWToken"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                IEnumerable <Marca> npList = await _npRepo.GetAllAsync(SD.MarcaAPIPath, HttpContext.Session.GetString("JWToken"));

                PatrimoniosVM objVM = new PatrimoniosVM()
                {
                    MarcasList = npList.Select(i => new SelectListItem
                    {
                        Text  = i.Nome,
                        Value = i.Id.ToString()
                    }),
                    Patrimonio = obj.Patrimonio
                };
                return(View(objVM));
            }
        }