示例#1
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));
        }
示例#2
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 }));
        }