public Task <bool> DeleteAsync(AssetMasterVM entity)
 {
     return(Task.Run(() =>
     {
         assetMasterRepo.Delete(new AssetMaster(), entity.ID);
         var depreciation = AssetDepreciationDetailsRepo.Filter(p => p.AssetMasterID == entity.ID).FirstOrDefault();
         if (depreciation != null)
         {
             AssetCompanyDetailsRepo.Delete(new AssetCompanyDetails(), depreciation.ID);
         }
         return true;
     }));
 }
        public async Task <IHttpActionResult> update([FromBody] AssetMasterVM entity)
        {
            if (!_AssetMasterService.CheckNameAndCode(entity.ID, entity.ARName, entity.LatName, entity.Code))
            {
                var result = await _AssetMasterService.UpdateAsync(entity);
                await LogData(entity.Code, entity.ID.ToString());

                return(Ok(result));
            }
            else
            {
                return(Ok(false));
            }
        }
        public async Task <IHttpActionResult> delete([FromBody] AssetMasterVM entity)
        {
            if (await _AssetMasterService.CheckAssetMasterForDeletion(entity.ID))
            {
                var result = await _AssetMasterService.DeleteAsync(entity);
                await LogData(entity.Code, entity.ID.ToString());

                return(Ok(result));
            }
            else
            {
                return(Ok(false));
            }
        }
        public async Task <IHttpActionResult> add([FromBody] AssetMasterVM entity)
        {
            if (!_AssetMasterService.CheckNameAndCode(entity.ID, entity.ARName, entity.LatName, entity.Code))
            {
                var result = await _AssetMasterService.InsertAsync(entity);
                await LogData(entity.Code, result.ToString());

                if (result != 0)
                {
                    return(Ok(true));
                }
            }
            return(Ok(false));
        }
        public Task <bool> UpdateAsync(AssetMasterVM entity)
        {
            return(Task.Run(() =>
            {
                if (entity.Asset_Base64_Photo != null)
                {
                    string base64 = entity.Asset_Base64_Photo;
                    entity.Asset_Base64_Photo = String.Format(base64);
                    base64 = base64.Remove(0, base64.IndexOf("base64,") + 7);
                    entity.AssetPhoto = Convert.FromBase64String(base64);
                }

                AssetMaster assetMaster = new AssetMaster
                {
                    ID = entity.ID,
                    Code = entity.Code,
                    ARName = entity.ARName,
                    LatName = entity.LatName,
                    AssetGroupID = entity.AssetGroupID,
                    AssetAccountID = entity.AssetAccountID,
                    AssetBrand = entity.AssetBrand,
                    AssetColor = entity.AssetColor,
                    AssetHeight = entity.AssetHeight,
                    AssetLocation = entity.AssetLocation,
                    AssetModel = entity.AssetModel,
                    AssetScreenNumber = entity.AssetScreenNumber,
                    AssetStatusID = entity.AssetStatusID,
                    AssetTypeID = entity.AssetTypeID,
                    AssetWeight = entity.AssetWeight,
                    AssetWidth = entity.AssetWidth,
                    Barcode = entity.Barcode,
                    ManufactureCompanyID = entity.ManufactureCompanyID,
                    OriginNationID = entity.OriginNationID,
                    SupplierCompanyID = entity.SupplierCompanyID,
                    DepreciationAccountID = entity.DepreciationAccountID,
                    TotalDepreciationAccountID = entity.TotalDepreciationAccountID,
                    ExpensesAccountID = entity.ExpensesAccountID,
                    CapitalProfitAccountID = entity.CapitalProfitAccountID,
                    CapitalLossAccountID = entity.CapitalLossAccountID,
                    AppraisalExcessAccountID = entity.AppraisalExcessAccountID,
                    ApprasialDeficitAccountID = entity.ApprasialDeficitAccountID,
                    AssetPhoto = entity.AssetPhoto,
                    AddedBy = entity.AddedBy,
                    AddedOn = entity.AddedOn,
                    UpdatedBy = entity.UpdatedBy,
                    UpdatedOn = DateTime.Now,
                    Notes = entity.Notes,
                    DepartmentID = entity.DepartmentID,
                    ManufactureDate = entity.ManufactureDate,
                    WarrantyNumber = entity.WarrantyNumber,
                    WarrantyStartDate = entity.WarrantyStartDate,
                    WarrantyEndDate = entity.WarrantyEndDate,
                    ReceivingDate = entity.ReceivingDate,
                    ReceivingNotes = entity.ReceivingNotes,
                    ContractNumber = entity.ContractNumber,

                    ContractDate = entity.ContractDate,
                    PurchasingDate = entity.PurchasingDate,
                    CustomsStatment = entity.CustomsStatment,
                    CustomsStatmentDate = entity.CustomsStatmentDate,

                    ShippingNumber = entity.ShippingNumber,
                    AssetShippingMethodID = entity.AssetShippingMethodID,
                    ShippingDate = entity.ShippingDate,
                    ImportLicenseNumber = entity.ImportLicenseNumber,
                    ShippingDestination = entity.ShippingDestination,
                    ShippingArrivalDate = entity.ShippingArrivalDate,
                    //Active = entity.Active,
                    //Position = entity.Position
                };
                assetMasterRepo.Update(assetMaster, assetMaster.ID);

                AssetDepreciationDetails assetDepreciationDetails = new AssetDepreciationDetails
                {
                    ID = entity.Depreciation.ID,
                    //Active = entity.Depreciation.Active,
                    AddedBy = entity.Depreciation.AddedBy,
                    AddedOn = entity.Depreciation.AddedOn,
                    AssetDepreciationTypeID = entity.Depreciation.AssetDepreciationTypeID,
                    //Position = entity.Depreciation.Position,
                    AssetLifeSpan = entity.Depreciation.AssetLifeSpan,
                    AssetLifeSpanUnitID = entity.Depreciation.AssetLifeSpanUnitID,
                    AssetMasterID = assetMaster.ID,
                    AssetScrapValue = entity.Depreciation.AssetScrapValue,
                    CurrencyID = entity.Depreciation.CurrencyID,
                    CurrencyRate = entity.Depreciation.CurrencyRate,
                    CurrentAssetValue = entity.Depreciation.CurrentAssetValue,
                    DepreciationStartDate = entity.Depreciation.DepreciationStartDate,
                    DepreciationTotals = entity.Depreciation.DepreciationTotals,
                    ExclusionsValue = entity.Depreciation.ExclusionsValue,
                    ExtraValue = entity.Depreciation.ExtraValue,
                    InitialAssetScrapValue = entity.Depreciation.InitialAssetScrapValue,
                    Notes = entity.Depreciation.Notes,
                    NotSubjectToDepreciation = entity.Depreciation.NotSubjectToDepreciation,
                    NotSubjectToRevaluation = entity.Depreciation.NotSubjectToRevaluation,
                    UpdatedBy = entity.Depreciation.UpdatedBy,
                    UpdatedOn = DateTime.Now
                };
                AssetDepreciationDetailsRepo.Update(assetDepreciationDetails, assetDepreciationDetails.ID);
                return true;
            }));
        }