예제 #1
0
        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);
        }
예제 #2
0
        public IActionResult GetAll()
        {
            var assets = _assetService.GetAll();

            //var model = _mapper.Map<IList<AssetMaintainDTO>>(assets);
            return(Ok(assets));
        }
예제 #3
0
 public AssetsModule(IAssetService assetService)
 {
     Get["/assets"] = _ =>
     {
         var assets = assetService.GetAll();
         return(Response.AsJson(assets));
     };
 }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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));
        }
예제 #7
0
 public IActionResult Get()
 {
     return(Ok(_assetService.GetAll()));
 }
예제 #8
0
        public IActionResult GetAll(GetAll criteria)
        {
            var response = _service.GetAll(criteria, _appSettings);

            return(Ok(response));
        }
예제 #9
0
        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));
        }
예제 #10
0
        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));
            }
        }