public UpdateDashboardResponse Handle(UpdateDashboardRequest request) { var response = new UpdateDashboardResponse(); response.Errors = Validate(request); if (response.HasErrors) { return(response); } try { var dashOrigin = _dashRepository.Get(request.DashBoard.Id); UpdateDashObject(dashOrigin, request.DashBoard); _dashRepository.Update(dashOrigin); return(response); } catch (Exception ex) { response.Errors.Add(new ErrorStatus("BAD_REQUEST")); return(response); } }
public CreateDashboardResponse Handle(CreateDashboardRequest request) { var response = new CreateDashboardResponse(); response.Errors = Validate(request); if (response.HasErrors) { return(response); } try { var dateNow = DateTime.Now; int dashId = _dashRepository.CreateAndGetId(new DashBoard { Name = request.DashName, DateModified = dateNow, DateCreated = dateNow, UserId = request.UserId }); response.Dashboard = _dashRepository.Get(dashId); } catch (Exception ex) { //response.Errors.Add(new ErrorStatus("BAD_REQUEST")); response.Errors.Add(new ErrorStatus(ex.Message)); } return(response); }
private IList <ErrorStatus> Validate(DeleteDashRequest request) { var errors = new List <ErrorStatus>(); var dash = _dashRepository.Get(request.DashboardId); if (dash == null) { errors.Add(new ErrorStatus("DASH_NOT_FOUND")); return(errors); } if (request.UserId != dash.UserId) { errors.Add(new ErrorStatus("UNAUTHORIZED_ACCESS")); return(errors); } return (errors); }