public bool UpdateDashboard(UpdateDashboardDto dashboard, string dashboardGUID, User user) { var origDashboard = _dashboardRepository.Get(dashboardGUID); if (origDashboard == null) { throw new NotFoundException("Invalid dashboardGUID"); } var perrel = _userDashRelRepository.Get(origDashboard.Id, user.Id); if (perrel == null || perrel.AuthoryLayer != (int)DashboardUserPermissions.CanModify) { throw new PermissionException("Don't have permission."); } origDashboard.Name = dashboard.Name; origDashboard.LastModifier = user; _dashboardRepository.Update(origDashboard); foreach (var rel in _reportDashboardRel.GetDashboardReports(origDashboard.Id)) { _reportDashboardRel.Remove(rel.Id); } foreach (var rel in dashboard.Reports) { var report = _reportRepository.Get(rel.ReportGUID); if (report == null) { continue; } _reportDashboardRel.Add(new ReportDashboardRel { Dashboard = origDashboard, Report = report, Position = rel.Position }); } return(true); }
public IActionResult UpdateDashboard([FromBody] UpdateDashboardDto dashboard, string dashboardGUID) { try { if (dashboard == null) { throw new BasicException("Invalid Dto"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } User user = _userRep.GetByEmailAdd(this.User.Claims.SingleOrDefault(x => x.Type == "EmailAddress").Value); _manager.UpdateDashboard(dashboard, dashboardGUID, user); return(NoContent()); } catch (BasicException ex) { _logger.LogError(ex.Message); return(BadRequest(ex.Message)); } catch (NotFoundException ex) { _logger.LogError(ex.Message); return(NotFound(ex.Message)); } catch (PermissionException ex) { _logger.LogError(ex.Message); return(Unauthorized()); } catch (Exception ex) { _logger.LogError(ex.Message); return(BadRequest()); } }