예제 #1
0
        public async Task <IActionResult> EditProject(Project_edit.Input Input, string Tags, IFormFile file)
        {
            var project = _ProjectService.GetById(Input.Id);

            if (project == null)
            {
                return(RedirectToAction("ListProjects"));
            }

            if (string.IsNullOrWhiteSpace(Input.Title) && string.IsNullOrEmpty(Input.Description))
            {
                return(RedirectToAction("EditProject", new { Id = Input.Id }));
            }

            project.Title      = Input.Title;
            project.Desciption = Input.Description;

            await _tagService.ClearTagsOnProject(project.Id);

            if (!string.IsNullOrWhiteSpace(Tags))
            {
                string[] tags = Tags.Split(",").Skip(1).ToArray();
                foreach (string item in tags)
                {
                    var t = _tagService.getByNorTag(item.ToUpper());
                    if (t == null)
                    {
                        return(RedirectToAction("CreateProject"));
                    }

                    project.TagLink.Add(new ProjectTag
                    {
                        project = project,
                        tag     = t
                    });
                }
            }

            //TODO make _environment to string and use _environment.WebRootPath
            //project.HTMLPath = Helper.HtmlManager.CreateHtml(Input.Context, Input.Title, @"\content\Projects\", _environment);
            Helper.HtmlManager.WriteHtml(project.HTMLPath, Input.Context, _environment);
            if (file != null)
            {
                Helper.ImageManager.DeleteImage(project.ImgPath, _environment);
                project.ImgPath = Helper.ImageManager.UploadImage(file: file, Input.Title, "/images/Uploaded/Projects/", _environment);
            }

            await _ProjectService.Edit(project);

            return(RedirectToAction("ListProjects"));
        }