Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] AssetType assetType)
        {
            if (id != assetType.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    AssetTypeManager.Update(assetType);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssetTypeExists(assetType.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(assetType));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, AssetType type)
        {
            try
            {
                AssetTypeManager.Update(type);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(AssetType assetType)
        {
            try
            {
                // call the AssetTypeManager to edit
                AssetTypeManager.Update(assetType);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Save(AssetTypeViewModel assetTypeVm)
        {
            ModelState.Remove("Id");

            if (ModelState.IsValid)
            {
                if (assetTypeVm.Id == 0)
                {
                    bool isShortNameExist = _assetTypeManager.IsShortNameExsit(assetTypeVm.ShortName);
                    if (isShortNameExist)
                    {
                        ViewBag.Message = "This Type Short Name already Exist";
                        return(View("AssetTypeForm"));
                    }
                    var assetType = new AssetType()
                    {
                        Id        = assetTypeVm.Id,
                        Name      = assetTypeVm.Name,
                        ShortName = assetTypeVm.ShortName,
                        Code      = assetTypeVm.Code
                    };
                    _assetTypeManager.Add(assetType);
                    ModelState.Clear();
                    return(View("AssetTypeForm"));
                }

                var assetTypeInDb = _assetTypeManager.Get(assetTypeVm.Id);
                assetTypeInDb.Id        = assetTypeVm.Id;
                assetTypeInDb.Name      = assetTypeVm.Name;
                assetTypeInDb.ShortName = assetTypeVm.ShortName;
                assetTypeInDb.Code      = assetTypeVm.Code;

                _assetTypeManager.Update(assetTypeInDb);
                ModelState.Clear();
                return(View("AssetTypeList"));
            }
            return(View("AssetTypeForm", assetTypeVm));
        }