public async Task <IActionResult> Edit(int id, TypeOfSupply typeOfSupply)
        {
            if (id != typeOfSupply.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    typeOfSupply.UpdateAt = DateTime.Now;
                    _context.Update(typeOfSupply);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("SuccessMessage", "Cập nhật thành công");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TypeOfSupplyExists(typeOfSupply.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeOfSupply));
        }
Exemple #2
0
 public TypeOfSupplyViewModel(TypeOfSupply typeOfSupply)
 {
     if (typeOfSupply != null)
     {
         Id          = typeOfSupply.Id;
         Name        = typeOfSupply.Name;
         Description = typeOfSupply.Description;
         material    = typeOfSupply.Materials;
     }
 }
        public async Task <IActionResult> Create(TypeOfSupply typeOfSupply)
        {
            if (ModelState.IsValid)
            {
                typeOfSupply.CreateAt = DateTime.Now;
                _context.Add(typeOfSupply);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("SuccessMessage", "Thêm mới thành công");
                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeOfSupply));
        }