public ApiResponse Update(AssetServiceLog assetServiceLog) { var validationError = ValidateUpdate(assetServiceLog); if (validationError.Count() == 0) { _faciTechDbContext.SaveChanges(); return(new ApiResponse(new { Id = assetServiceLog.Id })); } return(new ApiResponse(validationError)); }
private List <ErrorInfo> ValidateCreate(AssetServiceLog assetServiceLog) { List <ErrorInfo> errorInfos = new List <ErrorInfo>(); /* * errorInfos.Add(new ErrorInfo() * { * Key = "Name", Code = "UNIQUE_VIOLATION_ERROR", Description = "Name has to be unique" * }); */ return(errorInfos); }
public AssetServiceLog Map(AssetServiceLogApiModel assetServiceLogApiModel, AssetServiceLog assetServiceLog = null) { if (assetServiceLog == null) { assetServiceLog = new AssetServiceLog(); } assetServiceLog.Cost = assetServiceLogApiModel.Cost; assetServiceLog.InspectionDate = assetServiceLogApiModel.InspectionDate.ToDateTime().Value; assetServiceLog.NextInspectionDueOn = assetServiceLogApiModel.NextInspectionDueOn.ToDateTime(); assetServiceLog.Details = assetServiceLogApiModel.Details; return(assetServiceLog); }
public AssetServiceLogApiModel Map(AssetServiceLog assetServiceLog, AssetServiceLogApiModel assetServiceLogApiModel = null) { if (assetServiceLogApiModel == null) { assetServiceLogApiModel = new AssetServiceLogApiModel(); } assetServiceLogApiModel.Cost = assetServiceLog.Cost; assetServiceLogApiModel.InspectionDate = assetServiceLog.InspectionDate.ToDateString(); assetServiceLogApiModel.NextInspectionDueOn = assetServiceLog.NextInspectionDueOn.ToDateString(); assetServiceLogApiModel.Details = assetServiceLog.Details; return(assetServiceLogApiModel); }
public ApiResponse Add(Guid assetId, AssetServiceLog assetServiceLog) { var validationError = ValidateCreate(assetServiceLog); if (validationError.Count() == 0) { assetServiceLog.Id = Guid.NewGuid(); assetServiceLog.AssetId = assetId; _faciTechDbContext.AssetServiceLog.Add(assetServiceLog); _faciTechDbContext.SaveChanges(); return(new ApiResponse(new { Id = assetServiceLog.Id })); } return(new ApiResponse(validationError)); }
public ActionResult GetSingle(Guid id) { try { ApiResponse apiResponse = this._assetServiceLogService.GetSingle(id); AssetServiceLog assetServiceLog = apiResponse.GetData <AssetServiceLog>(); var assetServiceLogApiModel = _assetServiceLogMapper.Map(assetServiceLog); return(Ok(assetServiceLogApiModel)); } catch (Exception ex) { return(new UnknownErrorResult(ex, base._errorEnabled)); } }
public ActionResult Update(Guid id, AssetServiceLogApiModel assetServiceLogApiModel) { try { ApiResponse serviceResponse = this._assetServiceLogService.GetSingle(id); if (serviceResponse.IsSuccess() == false) { return(new ObjectNotFoundResult(serviceResponse)); } AssetServiceLog assetServiceLog = serviceResponse.GetData <AssetServiceLog>(); _assetServiceLogMapper.Map(assetServiceLogApiModel, assetServiceLog); serviceResponse = this._assetServiceLogService.Update(assetServiceLog); return(SendResponse(serviceResponse)); } catch (Exception ex) { return(new UnknownErrorResult(ex, base._errorEnabled)); } }
private List <ErrorInfo> ValidateUpdate(AssetServiceLog assetServiceLog) { List <ErrorInfo> errorInfos = new List <ErrorInfo>(); return(errorInfos); }