public void Save(AssetCategoryViewModel assetCategoryViewModel)
 {
     AssetCategory assetCat = new AssetCategory(assetCategoryViewModel.Id)
     {
         Name = assetCategoryViewModel.Name,
         Description=assetCategoryViewModel.Description,
         AssetType = _assetTypeRepository.GetById(assetCategoryViewModel.AssetTypeId)
     };
     _assetCategoryRepository.Save(assetCat);
 }
 private AssetCategoryViewModel Map(AssetCategory assetCategory)
 {
     AssetCategoryViewModel assetCategoryViewModel = new AssetCategoryViewModel();
     assetCategoryViewModel.Id = assetCategory.Id;
     assetCategoryViewModel.Name = assetCategory.Name;
     assetCategoryViewModel.Description = assetCategory.Description;
     if (assetCategory.AssetType != null)
        {
            assetCategoryViewModel.AssetTypeId = _assetTypeRepository.GetById(assetCategory.AssetType.Id).Id;
        }
     if (assetCategory.AssetType != null)
        {
            assetCategoryViewModel.AssetTypeName = _assetTypeRepository.GetById(assetCategory.AssetType.Id).Name;
        }
     if (assetCategory._Status == EntityStatus.Active)
         assetCategoryViewModel.IsActive = true;
        return assetCategoryViewModel;
     
 }
        public ActionResult CreateAssetCategory(AssetCategoryViewModel acvm)
        {
            ViewBag.AssetTypeList = _assetCategoryViewModelBuilder.AssetType();
            try
            {
                acvm.Id = Guid.NewGuid();
                _assetCategoryViewModelBuilder.Save(acvm);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Province", DateTime.Now);
                //_auditLogViewModelBuilder.addAuditLog(this.User.Identity.Name, "Create", "Asset Category", DateTime.Now);
                TempData["msg"] = "Asset Category Successfully Created";
                return RedirectToAction("listassetcategories");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                _log.Debug("Failed to create asset categories " + ve.Message);
                _log.Error("Failed to create asset categories" + ve.ToString());
               
                return View(acvm);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                _log.Debug("Failed to create asset categories " + ex.Message);
                _log.Error("Failed to create asset categories" + ex.ToString());
            
                return View(acvm);
            }

        }
        public ActionResult EditAssetCategory(AssetCategoryViewModel vm)
        {
            ViewBag.AssetTypeList = _assetCategoryViewModelBuilder.AssetType(); 
            try
            {
                _assetCategoryViewModelBuilder.Save(vm);
                _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Edit", "Asset Category", DateTime.Now);
                TempData["msg"] = "Asset Category Successfully Edited";

                return RedirectToAction("ListAssetCategories");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                _log.Debug("Failed to edit asset categories " + ve.Message);
                _log.Error("Failed to edit asset categories" + ve.ToString());
               
                return View();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                _log.Debug("Failed to edit asset categories " + ex.Message);
                _log.Error("Failed to edit asset categories" + ex.ToString());
                return View();
            }
        }