private async Task <Project> LoadProjectForDashboard(int id, BaseResponseModelGet <ProjectModel> response) { Project project = await Database.Project .Include(p => p.ProjectMetric).ThenInclude(pm => pm.Metric).ThenInclude(m => m.MetricType) .Include(p => p.ProjectMetric).ThenInclude(pm => pm.Metric).ThenInclude(m => m.MetricColumn) .Include(p => p.ProjectMetric).ThenInclude(pm => pm.ProjectMetricSnapshot).ThenInclude(pms => pms.ProjectMetricColumnValue) .FirstOrDefaultAsyncSpecial(a => a.Id == id, true); if (project == null) { response.Success = false; response.Message = "Unknown project!"; } else { if ((CurrentUser.RoleName == MainController.RoleUser && project.ProjectUser.All(p => p.UserId != CurrentUser.Id)) || (CurrentUser.RoleName != MainController.RoleUser && project.ProjectUser.All(u => u.User.CompanyId != CurrentUser.CompanyId))) { project = null; response.Success = false; response.Message = "You don't have access to this project!"; } } return(project); }
public async Task <BaseResponseModelGet <T> > Get <T>(int id, string jwt, string entity, bool lazy = true) { var result = new BaseResponseModelGet <T>(); await GetToAPI(id, GetParametersList(GetParameter("lazy", lazy.ToString())), async (httpResult) => { result = JsonConvert.DeserializeObject <BaseResponseModelGet <T> >(await httpResult.Content.ReadAsStringAsync()); }, entity, jwt : jwt); return(result); }
/// <summary> /// ziska uzivatele z API, kde jsou i overeny jeho prihlasovaci udaje /// </summary> /// <param name="model">data, ktere chci poslat na API, jejich vlastnosti musi odpovidat objektu z API</param> /// <returns></returns> public async Task <BaseResponseModelGet <UserIdentityModel> > AuthenticateUser(LoginViewModel model) { var result = new BaseResponseModelGet <UserIdentityModel>(); await PostToAPI(SerializeObjectToJSON(model), async httpResult => { result = JsonConvert.DeserializeObject <BaseResponseModelGet <UserIdentityModel> >(await httpResult.Content.ReadAsStringAsync()); }, "login"); return(result); }
public async Task <BaseResponseModelGet <UserModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <UserModel>(); User user = await Load(id, response); if (user != null) { response.Value = ConvertToModel(user); } return(response); }
public async Task <BaseResponseModelGet <MetricTypeModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <MetricTypeModel>(); MetricType metricType = await Load(id, response, false, lazy); if (metricType != null) { response.Value = ConvertToModel(metricType); } return(response); }
public async Task <BaseResponseModelGet <AffectedFieldModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <AffectedFieldModel>(); AffectedField affectedField = await Load(id, response, false); if (affectedField != null) { response.Value = ConvertToModel(affectedField); } return(response); }
public async Task <BaseResponseModelGet <AspiceVersionModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <AspiceVersionModel>(); AspiceVersion aspiceVersion = await Load(id, response, false); if (aspiceVersion != null) { response.Value = ConvertToModel(aspiceVersion); } return(response); }
public async Task <BaseResponseModelGet <ProjectMetricModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <ProjectMetricModel>(); ProjectMetric projectMetric = await Load(id, response); if (projectMetric != null) { response.Value = ConvertToModel(projectMetric); if (!lazy) { response.Value.Snapshots = GetSnapshots(projectMetric.ProjectMetricSnapshot); } } return(response); }
public async Task <BaseResponseModelGet <ProjectModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <ProjectModel>(); Project project = await Load(id, response, true, lazy); if (project != null) { response.Value = ConvertToModel(project); if (!lazy) { response.Value.ProjectUsers = GetProjectUsers(project.ProjectUser, true); response.Value.ProjectMetrics = GetProjectMetrics(project.ProjectMetric, true); } } return(response); }
/// <summary> /// pro ziskani dat na projektovou nastenku /// </summary> /// <param name="id">ID projektu</param> /// <returns></returns> public async Task <BaseResponseModelGet <ProjectModel> > Get(int id) { var response = new BaseResponseModelGet <ProjectModel>(); Project project = await LoadProjectForDashboard(id, response); if (project != null) { response.Value = ConvertToModel(project); response.Value.ProjectMetrics = GetProjectMetrics(project.ProjectMetric, true, true); for (int i = 0; i < response.Value.ProjectMetrics.Count; i++) { response.Value.ProjectMetrics[i].Snapshots = GetProjectMetricSnapshots(project.ProjectMetric.ElementAt(i).ProjectMetricSnapshot); } } return(response); }
public async Task <BaseResponseModelGet <MetricModel> > Get(int id, bool lazy) { var response = new BaseResponseModelGet <MetricModel>(); Metric metric = await Load(id, response, false, lazy); if (metric != null) { response.Value = ConvertToModel(metric); if (!lazy) { response.Value.MetricType = GetMetricType(metric.MetricType); response.Value.AspiceProcess = GetAspiceProcess(metric.AspiceProcess); response.Value.AffectedField = GetAffectedField(metric.AffectedField); response.Value.Columns = GetMetricColumns(metric.MetricColumn); } } return(response); }
/// <summary> /// zkontroluje uzivatele /// </summary> /// <param name="model">prijate informace o uzivateli</param> /// <returns></returns> public async Task <BaseResponseModelGet <UserIdentityModel> > CheckUser(LoginRequestModel model) { var result = new BaseResponseModelGet <UserIdentityModel> { Value = new UserIdentityModel() }; if (model.Validate()) { model.Username = model.Username.Trim(); model.Password = model.Password.Trim(); User user = await Database.User.Include(u => u.UserRole).AsNoTracking().FirstOrDefaultAsync(u => u.Username == model.Username); if (user != null) { if ((user.UseLdaplogin && await CheckLdapLogin(user.LdapUrl, model.Username, model.Password)) || ComparePasswords(user, model.Password)) { await CreateUserSession(user, result.Value); } else { result.Success = false; result.Message = "Incorrect credentials!"; } } else { result.Success = false; result.Message = "Unknown credentials!"; } } else { result.Success = false; result.Message = "Enter username and password!"; } return(result); }