public ActionResult Add() { var viewModel = new AddAssetFullViewModel { InventoryNumber = "0", Guarantee = 0, Price = 1 }; var user = this.userService.GetById(this.User.Identity.GetUserId()); if (!this.IsMegaAdmin()) { viewModel.Currency = this.currencyService.GetAll() .Where(x => x.OrganisationId == user.Site.OrganisationId).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); } else { viewModel.Currency = new List <CurrencyViewModel>(); } return(View(viewModel)); }
public ActionResult Add(AddAssetFullViewModel model) { var exist = assetService.Exist(model.InventoryNumber); if (!ModelState.IsValid || model.SiteId == 0 || exist) { if (exist) { this.ModelState.AddModelError("", AssetTr.ExistAssetWithIN); } if (model.SiteId == 0) { this.ModelState.AddModelError("", AssetTr.SiteIsRequired); } //Add all currencies to viewmodel var user = this.userService.GetById(this.User.Identity.GetUserId()); if (!this.IsMegaAdmin()) { model.Currency = this.currencyService.GetAll() .Where(x => x.OrganisationId == user.Site.OrganisationId).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); } else { var site = this.siteService.GetById(model.SiteId); if (site != null) { model.Currency = this.currencyService.GetAll().ToList() .Where(x => x.OrganisationId == site.OrganisationId).ToList() .ConvertAll(x => new CurrencyViewModel { Code = x.Code, Id = x.Id }).ToList(); } else { model.Currency = new List <CurrencyViewModel>(); } } return(View(model)); } var asset = new Asset { Brand = model.Brand, Guarantee = model.Guarantee, InventoryNumber = model.InventoryNumber, Model = model.ItemModel, Price = new Price { Value = model.Price, CurrencyId = model.SelectedCurrency }, Producer = model.Producer, Status = "Active", Type = model.Type, }; if (model.LocationId != null) { asset.LocationId = model.LocationId; } if (model.UserId != null) { asset.UserId = model.UserId; asset.SiteId = this.userService.GetById(model.UserId).SiteId; } else { asset.SiteId = model.SiteId; } this.assetService.Add(asset); //Create asset history this.assetHistoryService.Add( new AssetHistory { AssetId = asset.InventoryNumber }); //Add a first history row this.assetHistoryService.AddHistoryRow(new HistoryRow { Content = "The asset was acquired.", Date = DateTime.Now }, asset.InventoryNumber); return(Redirect("/AssetsActions/Asset/GetAll")); }