Exemplo n.º 1
0
        public async Task <IActionResult> Update(AssetsDTO assetsDTO)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(assetsDTO));
                }

                StatusModel       statusModel       = (StatusModel)Enum.Parse(typeof(StatusModel), assetsDTO.Status);
                LocationModel     locationModel     = (LocationModel)Enum.Parse(typeof(LocationModel), assetsDTO.Location);
                TypeModel         typeModel         = (TypeModel)Enum.Parse(typeof(TypeModel), assetsDTO.Type);
                AvailabilityModel availabilityModel = (AvailabilityModel)Enum.Parse(typeof(AvailabilityModel), assetsDTO.IsAvailable);
                AvailabilityModel assigned          = (AvailabilityModel)Enum.Parse(typeof(AvailabilityModel), assetsDTO.IsAssinged);

                assetsDTO.Status      = statusModel.ToString();
                assetsDTO.Location    = locationModel.ToString();
                assetsDTO.Type        = typeModel.ToString();
                assetsDTO.IsAvailable = availabilityModel.ToString();
                assetsDTO.IsAssinged  = assetsDTO.ToString();

                var asset = new Asset()
                {
                    Id          = assetsDTO.Id,
                    Brand       = assetsDTO.Brand,
                    HostName    = assetsDTO.HostName,
                    AssetNo     = assetsDTO.AssetNo,
                    ExpressCode = assetsDTO.ExpressCode,
                    IsAvailable = availabilityModel.ToString(),
                    Location    = locationModel.ToString(),
                    Status      = statusModel.ToString(),
                    Model       = assetsDTO.Model,
                    Remarks     = assetsDTO.Remarks,
                    SerialNo    = assetsDTO.SerialNo,
                    Type        = typeModel.ToString(),
                    IsAssinged  = assigned.ToString()
                };

                var result = await _assetInterface.EditAsset(asset, Request.Cookies["AssetReference"].ToString());

                return(View(assetsDTO));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in AssetsController||Update ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AssignAssetsUsers(string assetId)
        {
            try
            {
                var asset = await _assetInterface.GetAsset(assetId, Request.Cookies["AssetReference"].ToString());

                if (asset == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var user = await _userStaffInterface.GetUserStaffs(Request.Cookies["AssetReference"].ToString());

                if (user == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                //Map the objects results to corresponding DTO's
                AssetsDTO           assetsDTO    = _mapper.Map <AssetsDTO>(asset);
                List <UserStaffDTO> userStaffDTO = _mapper.Map <List <UserStaffDTO> >(user);

                //Instantiate AssetsUserVIewModel
                var assetsUserVIewModel = new AssetsUserVIewModel()
                {
                    AssetsDTO     = assetsDTO,
                    UserStaffDTOs = userStaffDTO
                };

                //Set the Date to its initial value
                var date = DateTime.Now;
                ViewBag.Date = date.ToString("yyyy-MM-dd");

                ViewBag.AssetId = assetsUserVIewModel.AssetsDTO.Id;

                return(View(assetsUserVIewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in AssetsController||AssignAssetsUsers ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ViewAsset(string assetId)
        {
            try
            {
                if (Request.Cookies["AssetReference"] == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var asset = await _assetInterface.GetAsset(assetId, Request.Cookies["AssetReference"].ToString());

                if (asset == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                var userAssets = await _userAssetsInterface.GetAssetsOfUser(assetId, Request.Cookies["AssetReference"].ToString());

                if (userAssets == null)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                //Map the objects results to corresponding DTO's
                AssetsDTO         assetsDTO      = _mapper.Map <AssetsDTO>(asset);
                List <UserAssets> userAssetsDTOs = _mapper.Map <List <UserAssets> >(userAssets);

                //Instantiate AssetsUserVIewModel
                var viewAssetsUserViewModel = new ViewAssetsUserViewModel()
                {
                    AssetsDTO  = assetsDTO,
                    UserAssets = userAssetsDTOs
                };

                return(View(viewAssetsUserViewModel));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error encountered in AssetsController||ViewAsset ErrorMessage: {ex.Message}");
                return(RedirectToAction("Index", "Error"));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Obtener Activos Fijos.
        /// </summary>
        public IList <AssetsDTO> GetAssets(string lStrOcrCode)
        {
            SAPbobsCOM.Recordset lObjRecordset = null;
            IList <AssetsDTO>    lLstAssetsDTO = new List <AssetsDTO>();

            try
            {
                Dictionary <string, string> lLstStrParameters = new Dictionary <string, string>();
                lLstStrParameters.Add("OcrCode", lStrOcrCode);
                string lStrQuery = this.GetSQL("GetAssets").Inject(lLstStrParameters);
                //this.UIAPIRawForm.DataSources.DataTables.Item("RESULT").ExecuteQuery(lStrQuery);

                lObjRecordset = (SAPbobsCOM.Recordset)DIApplication.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                lObjRecordset.DoQuery(lStrQuery);

                if (lObjRecordset.RecordCount > 0)
                {
                    for (int i = 0; i < lObjRecordset.RecordCount; i++)
                    {
                        AssetsDTO lObjAssetDTO = new AssetsDTO();
                        lObjAssetDTO.FrgnName = lObjRecordset.Fields.Item("FrgnName").Value.ToString();
                        lObjAssetDTO.OcrCode  = lObjRecordset.Fields.Item("OcrCode").Value.ToString();
                        lObjAssetDTO.PrcCode  = lObjRecordset.Fields.Item("PrcCode").Value.ToString();
                        lLstAssetsDTO.Add(lObjAssetDTO);
                        lObjRecordset.MoveNext();
                    }
                }
            }
            catch (Exception ex)
            {
                UIApplication.ShowMessageBox(string.Format("InitDataSourcesException: {0}", ex.Message));
                LogService.WriteError("PurchasesDAO (GetAssets): " + ex.Message);
                LogService.WriteError(ex);
            }
            finally
            {
                MemoryUtility.ReleaseComObject(lObjRecordset);
            }

            return(lLstAssetsDTO);
        }