public async Task <IActionResult> Index(int?projectId)
        {
            FormDesignTemplateModelBE model = new FormDesignTemplateModelBE();

            using (var httpClient = new HttpClient())
            {
                string url = DBConfiguration.WebAPIHostingURL;
                if (!string.IsNullOrWhiteSpace(url))
                {
                    string webAPIURL = string.Empty;
                    if (projectId != null)
                    {
                        webAPIURL = string.Format("{0}form/GetForms/{1}", url, projectId.Value);
                    }
                    else
                    {
                        webAPIURL = string.Format("{0}form/GetForms", url);
                    }
                    using (var response = await httpClient.GetAsync(webAPIURL))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        List <SelectListItem> forms = JsonConvert.DeserializeObject <List <SelectListItem> >(apiResponse);
                        forms.Insert(0, new SelectListItem {
                            Text = "--Select Form--", Value = "-1"
                        });
                        ViewData["FormList"] = forms;
                    }
                }
                ViewData["SaveFormDataURL"]     = string.Format("{0}form/SaveFormData", url);
                ViewData["CompleteFormDataURL"] = string.Format("{0}form/CompleteFormData", url);
            }

            if (projectId != null)
            {
                ProjectBE projectBE = FormLogic.FetchProject(projectId.Value);
                if (projectBE != null)
                {
                    model.Project            = projectBE.Project;
                    model.ProjectDescription = projectBE.Description;
                    model.ProjectId          = projectId.Value;
                }
            }

            bool isAjaxRequest = HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";

            if (isAjaxRequest)
            {
                return(PartialView(model));
            }
            else
            {
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditProject(int projectID)
        {
            ProjectModel model = new ProjectModel();

            ProjectBE project = FormLogic.FetchProject(projectID);

            if (Functions.IsNull(project))
            {
                project = new ProjectBE();
            }
            BusinessEntityHelper.ConvertBEToBEForUI <ProjectBE, ProjectModel>(project, model);
            using (var httpClient = new HttpClient())
            {
                string url = DBConfiguration.WebAPIHostingURL;
                if (!string.IsNullOrWhiteSpace(url))
                {
                    string webAPIURL = string.Empty;

                    webAPIURL = string.Format("{0}form/GetForms", url);

                    using (var response = await httpClient.GetAsync(webAPIURL))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        List <SelectListItem> forms = JsonConvert.DeserializeObject <List <SelectListItem> >(apiResponse);
                        ViewData["FormList"] = forms;
                    }

                    webAPIURL = string.Format("{0}project/GetClient", url);

                    using (var response = await httpClient.GetAsync(webAPIURL))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        List <SelectListItem> client = JsonConvert.DeserializeObject <List <SelectListItem> >(apiResponse);
                        ViewData["ClientList"] = client;
                    }
                }
            }
            List <ProjectFormBE> list = FormLogic.BlockFetchProjectForm(projectID, 1, int.MaxValue, out int totalRecords);

            if (list != null)
            {
                model.ProjectFormList = list.Select(m => m.FormId).ToList();
            }


            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult EditProject(ProjectModel model)
        {
            bool success = false;
            int  id      = 0;

            ProjectBE project = FormLogic.FetchProject(model.ID);

            if (Functions.IsNull(project))
            {
                project = new ProjectBE();
                BusinessEntityHelper.ConvertBEToBEForUI <ProjectModel, ProjectBE>(model, project);
                project.CreatedDateTime     = DateTime.Now;
                project.LastUpdatedDateTime = DateTime.Now;
                project.CreatedBy           = "Habitat";
                project.UpdatedBy           = "Habitat";
                project.ID       = project.ID < 0 ? 0 : project.ID;
                project.ClientID = project.ClientID < 0 ? 0 : project.ClientID;
                success          = FormLogic.AddProject(project, out id);
            }
            else
            {
                project.Project             = model.Project;
                project.ProjectName         = model.ProjectName;
                project.Description         = model.Description;
                project.Manager             = model.Manager;
                project.SiteAddress         = model.SiteAddress;
                project.SitePostcode        = model.SitePostcode;
                project.ClientID            = model.ClientID;
                project.LastUpdatedDateTime = DateTime.Now;
                project.ClientID            = project.ClientID < 0 ? 0 : project.ClientID;
                project.UpdatedBy           = "Habitat";
                success = FormLogic.UpdateProject(project);
            }


            if (success)
            {
                int projectID = model.ID > 0 ? model.ID : id;
                success = FormLogic.SaveProjectForm(projectID, model.ProjectFormList != null ? string.Join(',', model.ProjectFormList) : string.Empty);
            }

            return(Json(new { success, id }));
        }