public async Task <AssetModelViewModel> GetAssetModelAsync(int id) { _logger.LogInformation("GetAssetModelAsync called."); var model = await _asyncRepository.GetByIdAsync(id); var modelVM = new AssetModelViewModel() { Id = model.Id, Name = model.Name, ManufacturerId = model.ManufacturerId, CategoryId = model.CategoryId, ModelNumber = model.ModelNumber, DepreciationId = model.DepreciationId, Eol = model.Eol, Image = model.Image, DeprecatedMacAdress = model.DeprecatedMacAdress, Notes = model.Notes, Requestable = model.Requestable, CreatedAt = model.CreatedAt, UpdatedAt = model.UpdatedAt, UpdatedBy = model.UpdatedBy }; return(modelVM); }
public async Task <IEnumerable <AssetModelViewModel> > GetAllModelAsync() { _logger.LogInformation("GetAllModelAsync called."); var allAssetModel = await _asyncRepository.ListAllAsync(); var modelViewList = new List <AssetModelViewModel>(); foreach (var model in allAssetModel) { var modelView = new AssetModelViewModel() { Id = model.Id, Name = model.Name, ManufacturerId = model.ManufacturerId, CategoryId = model.CategoryId, ModelNumber = model.ModelNumber, DepreciationId = model.DepreciationId, Eol = model.Eol, Image = model.Image, DeprecatedMacAdress = model.DeprecatedMacAdress, Notes = model.Notes, Requestable = model.Requestable }; modelViewList.Add(modelView); } return(modelViewList); }
public async Task <IActionResult> Delete(int id, AssetModelViewModel model) { if (id == model.Id && model != null) { await _assetModelViewModelService.DeleteAssetModelAsync(model.Id); return(RedirectToAction(nameof(Index))); } return(View()); }
public ActionResult Save(AssetModelViewModel assetModelVm) { var assetModelVmforDropdown = new AssetModelViewModel() { AssetGroups = _assetGroupManager.GetAll(), AssetManufacurers = new List <AssetManufacurer>() { } }; ModelState.Remove("Id"); if (ModelState.IsValid) { if (assetModelVm.Id == 0) { bool isShortNameExist = _assetModelManager.IsShortNameExist(assetModelVm.ShortName, assetModelVm.AssetGroupId, assetModelVm.AssetManufacurerId); if (isShortNameExist) { ViewBag.Message = "This Organization Short Name already Exist"; return(View("AssetModelForm", assetModelVmforDropdown)); } var assetModel = new AssetModel() { Name = assetModelVm.Name, ShortName = assetModelVm.ShortName, Code = assetModelVm.Code, Description = assetModelVm.Description, AssetGroupId = assetModelVm.AssetGroupId, AssetManufacurerId = assetModelVm.AssetManufacurerId }; _assetModelManager.Add(assetModel); ModelState.Clear(); return(View("AssetModelForm", assetModelVmforDropdown)); } var modelInDb = _assetModelManager.Get(assetModelVm.Id); modelInDb.Id = assetModelVm.Id; modelInDb.Name = assetModelVm.Name; modelInDb.ShortName = assetModelVm.ShortName; modelInDb.Code = assetModelVm.Code; modelInDb.Description = assetModelVm.Description; modelInDb.AssetGroupId = assetModelVm.AssetGroupId; modelInDb.AssetManufacurerId = assetModelVm.AssetManufacurerId; _assetModelManager.Update(modelInDb); ModelState.Clear(); return(View("AssetModelList")); } return(View("AssetModelForm", assetModelVmforDropdown)); }
public async Task <IActionResult> Create(AssetModelViewModel model) { string userId = User.Identity.Name; if (ModelState.IsValid) { await _assetModelViewModelService.AddAssetModelAsync(model, userId); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public ActionResult New() { var assetModelVm = new AssetModelViewModel() { AssetGroups = _assetGroupManager.GetAll(), AssetManufacurers = new List <AssetManufacurer>() { } }; return(View("AssetModelForm", assetModelVm)); }
public async Task UpdateAssetModelAsync(AssetModelViewModel assetModelViewModel, string userId) { _logger.LogInformation("UpdateAssetModelAsync called."); var model = new AssetModels() { Id = assetModelViewModel.Id, Name = assetModelViewModel.Name, ManufacturerId = assetModelViewModel.ManufacturerId, CategoryId = assetModelViewModel.CategoryId, ModelNumber = assetModelViewModel.ModelNumber, DepreciationId = assetModelViewModel.DepreciationId, Eol = assetModelViewModel.Eol, Image = assetModelViewModel.Image, DeprecatedMacAdress = assetModelViewModel.DeprecatedMacAdress, Notes = assetModelViewModel.Notes, Requestable = assetModelViewModel.Requestable, UpdatedAt = DateTime.Now, UpdatedBy = userId }; await _asyncRepository.UpdateAsync(model); }
public ActionResult Edit(int id) { var model = _assetModelManager.Get(id); if (model == null) { return(HttpNotFound()); } var viewModel = new AssetModelViewModel() { Name = model.Name, ShortName = model.ShortName, Code = model.Code, Description = model.Description, AssetGroupId = model.AssetGroupId, AssetManufacurerId = model.AssetManufacurerId, AssetGroups = _assetGroupManager.GetAll(), AssetManufacurers = _manufacturerManager.GetManufacurersByGroupId(model.AssetGroupId) }; return(View("AssetModelForm", viewModel)); }
public void CreateAssetModel(AssetModelViewModel assetModelViewModel) { assetModelRepository.Add(Mapper.Map <AssetModelViewModel, AssetModel>(assetModelViewModel)); }