public void UpdateAssetService() { var asset = _assetService.GetAll().FirstOrDefault(); if (asset != null) { asset.Name = "Unit test update"; _assetService.Update(asset); _assetService.SaveChanges(); } Assert.AreEqual("Unit test update", asset.Name); }
public IActionResult GetAll() { var assets = _assetService.GetAll(); //var model = _mapper.Map<IList<AssetMaintainDTO>>(assets); return(Ok(assets)); }
public AssetsModule(IAssetService assetService) { Get["/assets"] = _ => { var assets = assetService.GetAll(); return(Response.AsJson(assets)); }; }
public async Task <IActionResult> Get() { try { var data = await _assettService.GetAll(); return(new OkObjectResult(data)); } catch (Exception ex) { return(StatusCode(500, "Internal server error" + ex.Message)); } }
private SummaryModel GetSummaryModelForTransactions(IEnumerable <DailyTransactionBlockViewModel> transactions) { var totalSpent = transactions.Sum(x => x.TotalSpent); var totalReceived = transactions.Sum(x => x.TotalReceived); var avgDailySpend = Math.Round(transactions.Average(x => x.TotalSpent), 0); var capital = totalReceived - totalSpent; var capitalBeforeSpend = capital; var spendingSuggestions = new List <SpendModel>(); while (capital > 0) { var spendIdea = _spendService.GetRandomIdea(); spendingSuggestions.Add(spendIdea); capital = capital - spendIdea.Price; } var summary = new SummaryModel { TotalSpent = totalSpent, TotalReceived = totalReceived, AverageDailySpend = avgDailySpend, Capital = capitalBeforeSpend, SpendingSuggestions = spendingSuggestions }; var assets = _assetService.GetAll(); summary.TotalAssetWorth = assets.Sum(a => a.Worth); return(summary); }
public IActionResult GetAll() { var assets = _assetService.GetAll(); var assetDtos = _mapper.Map <IList <Responses.AssetDto> >(assets); foreach (var assetDto in assetDtos) { var user = _userManager.Users.FirstOrDefault(x => x.Id == assetDto.CreatedBy); if (user == null) { continue; } assetDto.CreatedBy = user.FirstName + " " + user.LastName; user = _userManager.Users.FirstOrDefault(x => x.Id == assetDto.ModifiedBy); if (user == null) { continue; } assetDto.ModifiedBy = user.FirstName + " " + user.LastName; } return(Ok(assetDtos)); }
public IActionResult Get() { return(Ok(_assetService.GetAll())); }
public IActionResult GetAll(GetAll criteria) { var response = _service.GetAll(criteria, _appSettings); return(Ok(response)); }
public ActionResult ListReport(int id) { Asset temp = _assetService.GetById(id); string assetCode = temp.AssetCode; List <Asset> assetModel = _assetService.GetAll().Where(a => a.Active).ToList(); if (assetCode.StartsWith("A")) { assetModel = _assetService.GetAllAssetIntoArea(temp.ID, temp.AreaID).ToList(); temp.Name = "Thiết bị khác"; assetModel.Add(temp); List <int> listID = new List <int>(); List <int> listIDReport = new List <int>(); foreach (var a in assetModel) { var report = _reportService.GetReportByConditions(a.ID, new string[] { "Asset" }); if (report != null) { listID.Add(a.ID); } else { listIDReport.Add(a.ID); } } ViewBag.listIDReport = listIDReport; ViewBag.listAssetID = listID; } else { TempData["assetID"] = temp.ID; return(RedirectToAction("Create")); } var assetViewModel = Mapper.Map <IEnumerable <Asset>, IEnumerable <AssetViewModel> >(assetModel); //list pageSize List <SelectListItem> listStatus = new List <SelectListItem>(); listStatus.Add(new SelectListItem { Text = "--All--", Value = "0" }); listStatus.Add(new SelectListItem { Text = "Opening", Value = "1" }); listStatus.Add(new SelectListItem { Text = "Processing", Value = "2" }); listStatus.Add(new SelectListItem { Text = "Done", Value = "3" }); listStatus.Add(new SelectListItem { Text = "Upwork", Value = "4" }); listStatus.Add(new SelectListItem { Text = "Cancel", Value = "5" }); // Set ViewBag ViewBag.listStatus = listStatus; ViewBag.isCreateSuccess = false; return(View(assetViewModel)); }
public ActionResult Create(AssetViewModel assetViewModel, int?idArea, int SelectedOption) { var validateMail = _assetService.GetAll(new string[] { "Area", "Area.Location" }).FirstOrDefault (x => x.Name == assetViewModel.Name && x.Area.ID == assetViewModel.AreaID && x.ID != assetViewModel.ID); if (validateMail != null) { ModelState.AddModelError("Name", "Name already exists in Area"); } var listAttribute = _assetAttributeService.GetAssetAttributes(assetViewModel.AssetTypeID); string assetTypeCode = ""; assetTypeCode = _assetService.GetStringAssetCode(SelectedOption); if (listAttribute.Count() > 0) { if (ModelState.IsValid) { assetViewModel.Active = true; assetViewModel.CreatedAt = DateTime.Now; assetViewModel.UpdatedAt = DateTime.Now; assetViewModel.AssetCode = assetTypeCode; TempData["idArea"] = idArea; return(RedirectToAction("CreateAttributeValue", assetViewModel)); } var areas = _areaService.GetAll(); var assetTypes = _assetTypeService.GetAll(); ViewBag.AreaID = new SelectList(areas, "ID", "AreaCode"); ViewBag.AssetTypeID = new SelectList(assetTypes, "ID", "Name"); return(View(assetViewModel)); } else { if (ModelState.IsValid) { Asset asset = new Asset() { AssetTypeID = assetViewModel.AssetTypeID, AreaID = assetViewModel.AreaID, Name = assetViewModel.Name, AssetCode = assetTypeCode, StartDate = assetViewModel.StartDate, Quantity = assetViewModel.Quantity, Description = assetViewModel.Description, ApplicationUserID = Convert.ToInt32(User.Identity.GetUserId()), Active = true, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; var checkAdd = _assetService.Add(asset, new List <AssetAttributeValue>()); if (checkAdd) { SetAlert("Add Asset success", "success"); } else { SetAlert("Add Asset error", "error"); } if (idArea != null) { return(RedirectToAction("AssetArea", "Asset", new { id = idArea })); } else { return(RedirectToAction("Index")); } } var areas = _areaService.GetAll(); var assetTypes = _assetTypeService.GetAll(); ViewBag.AreaID = new SelectList(areas, "ID", "AreaCode"); ViewBag.AssetTypeID = new SelectList(assetTypes, "ID", "Name"); return(View(assetViewModel)); } }