Exemplo n.º 1
0
        public async Task <IActionResult> DeleteFormComponentFromProject([FromBody] ProjectFormComponentModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsProject project = _repository.GetProjectbyProjectName(model.ProjectName);
                if (project == null)
                {
                    return(BadRequest("Cannot find the Project"));
                }

                FormComponent form = _repository.GetFormComponentbyName(model.FormComponentName);
                if (form == null)
                {
                    return(BadRequest("Cannot find the FormComponent"));
                }

                ProjectFormComponent pf = project.ProjectFormComponents.Where(p => p.FormComponentId == form.FormComponentId).FirstOrDefault();

                if (pf == null)
                {
                    return(BadRequest("Project doesn't contian FormComponent"));
                }

                project.ProjectFormComponents.Remove(pf);
                _repository.Save();
                return(Ok("FormComponent has been deleted from Project"));
            }
            return(BadRequest());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddFormComponentToProject([FromBody] ProjectFormComponentModel model)
        {
            if (ModelState.IsValid)
            {
                CoalyticsProject project = _repository.GetProjectbyProjectName(model.ProjectName);
                if (project == null)
                {
                    return(BadRequest("Cannot find the Project"));
                }

                FormComponent form = _repository.GetFormComponentbyName(model.FormComponentName);
                if (form == null)
                {
                    return(BadRequest("Cannot find the FormComponent"));
                }

                ProjectFormComponent pf = project.ProjectFormComponents.Where(p => p.FormComponentId == form.FormComponentId).FirstOrDefault();

                if (pf != null)
                {
                    return(BadRequest("Project already contins FormComponent"));
                }

                project.ProjectFormComponents.Add(new ProjectFormComponent()
                {
                    ProjectId       = project.ProjectId,
                    FormComponentId = form.FormComponentId
                });

                _repository.Save();
                return(Ok("FormComponent has been Added for Project"));
            }
            return(BadRequest());
        }