public ValueDataResponse <AssetLocation> UpdateAssetLocation(UpsertAssetLocation asset) { // AssetLocation assetInfo = _mapper.Map<AssetLocation>(asset); return(_unitOfWork.Assets.UpdateAssetLocation(asset)); }
public ValueDataResponse <AssetLocation> UpdateAssetLocation(UpsertAssetLocation asset) { ValueDataResponse <AssetLocation> response = new ValueDataResponse <AssetLocation>(); try { AssetLocation assetInfo = _mapper.Map <AssetLocation>(asset); var assetExists = _appContext.AssetLocations.Where(x => x.Id != asset.Id && x.AssetRef == asset.AssetRef).FirstOrDefault(); if (assetExists == null) { var result = _appContext.AssetLocations.Where(x => x.Id == asset.Id).FirstOrDefault(); if (result != null) { //result.SiteId = asset.SiteId; //result.ProjectId = asset.ProjectId; result.LocationId = asset.LocationId; result.AstGroupId = asset.AstGroupId; result.AstTradeId = asset.AstTradeId; result.Name1 = asset.Name1; result.Name2 = asset.Name2; result.AssetRef = asset.AssetRef; result.AstCounter = asset.AstCounter; result.AstFixedDate = asset.AstFixedDate; result.AssetSize = asset.AssetSize; result.AssetMake = asset.AssetMake; result.AssetModel = asset.AssetModel; result.AssetType = asset.AssetType; result.AssetCapacity = asset.AssetCapacity; result.IsActive = asset.IsActive; result.CreatedBy = asset.CreatedBy; result.CreatedDate = asset.CreatedDate; result.UpdatedBy = asset.UpdatedBy; result.UpdatedDate = asset.UpdatedDate; result.DaysApplicable = asset.DaysApplicable; foreach (var req in asset.AssetRepositories) { if (req.FileName != null) { string ModuleName = "Assets"; var now = DateTime.Now; var yearName = now.ToString("yyyy"); var monthName = now.Month.ToString("d2"); var dayName = now.ToString("dd"); FileUploadService repo = new FileUploadService(); string FolderLocation = "FileRepository"; string ServerRootPath = _config.Value.ServerRootPath; string Location = ServerRootPath + @"\" + FolderLocation + @"\" + yearName + @"\" + monthName + @"\" + dayName + @"\" + ModuleName; byte[] FileBytes = Convert.FromBase64String(req.FileName); req.FileName = repo.UploadFile(FileBytes, req.FileExtention, Location); req.FileLocation = Path.Combine(yearName, monthName, dayName, ModuleName); AssetFileRepository pros = new AssetFileRepository(); { pros.AssetId = assetInfo.Id; pros.FileName = req.FileName; pros.FileLocation = req.FileLocation; pros.FileExtention = req.FileExtention; pros.DocumentType = req.DocumentTypeId; pros.CreatedBy = req.CreatedBy; pros.CreatedDate = DateTime.Now; pros.UpdatedBy = req.UpdatedBy; pros.UpdatedDate = DateTime.Now; } _appContext.AssetFileRepositories.Add(pros); } } _appContext.SaveChanges(); response.Result = result; response.IsSuccess = true; response.AffectedRecords = 1; response.EndUserMessage = "Asset Updated Successfully"; } else { response.IsSuccess = true; response.AffectedRecords = 0; response.EndUserMessage = "Asset Updation Failed"; } } else { response.IsSuccess = false; response.AffectedRecords = 0; response.EndUserMessage = "Asset Reference Already Exists"; } } catch (Exception ex) { response.IsSuccess = false; response.AffectedRecords = 0; response.EndUserMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message; response.Exception = ex; } return(response); }
public ValueDataResponse <AssetLocation> InsertAssetLocation(UpsertAssetLocation asset) { return(_unitOfWork.Assets.InsertAssetLocation(asset)); }