コード例 #1
0
        public async Task <IActionResult> Create(ProjectModel model, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                var newProject = new Project();
                newProject.ProjectNumber   = model.ProjectNumber;
                newProject.ProjectName     = model.ProjectName;
                newProject.StockLength     = model.StockLength;
                newProject.StandardsType   = model.StandardsType;
                newProject.AccessoriesList = model.AccessoriesList;
                newProject.SuportBar       = model.SuportBar;
                newProject.TitleBlock      = model.TitleBlock;
                newProject.Description     = model.Description;
                newProject.Link            = model.Link;
                newProject = _projectData.Add(newProject);
                //_projectData.commit();
                var userid = _userManager.GetUserId(HttpContext.User);

                //Attachments Upload.
                if (file == null || file.Length == 0)
                {
                    Content("file not found");
                }
                else
                {
                    var    webRoot  = _env.WebRootPath;
                    string userId   = Convert.ToString(userid);
                    var    dateTime = DateTime.Now.ToString("dd-mm-yyyy");
                    if (!System.IO.Directory.Exists(webRoot + "/UserFiles/"))
                    {
                        System.IO.Directory.CreateDirectory(webRoot + "/UserFiles/");
                    }
                    if (!System.IO.Directory.Exists(webRoot + "/UserFiles/" + userId + "/" + dateTime + "/"))
                    {
                        System.IO.Directory.CreateDirectory(webRoot + "/UserFiles/" + userId + "/" + dateTime + "/");
                    }

                    //Creating dynamic folders for every user and every day
                    var path = Path.Combine(
                        Directory.GetCurrentDirectory(), "wwwroot" + "/UserFiles/" + userId + "/" + dateTime + "/", file.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    newProject.AttachmentName = path;
                }
                newProject.UserId = userid;

                //Save the project in db.
                _projectData.commit();

                //Once record is saved view page redirected to Details.
                return(RedirectToAction("Details"));
            }
            return(View());
        }
コード例 #2
0
        public IActionResult AddProject(String projectName)
        {
            var result = _projectData.Add(new Project
            {
                Title      = projectName,
                CreateDate = DateTime.Now
            });

            if (!result)
            {
                return(RedirectToAction("Error", "Home", new ErrorViewModel {
                    Error = "مشکل در ایجاد پروژه جدید!"
                }));
            }
            return(RedirectToAction("AdminPanel"));
        }
コード例 #3
0
        public IActionResult AdminConsole(ProjectEditModel model)
        {
            var newProject = new Project();

            newProject.Title             = model.Title;
            newProject.ShortDescription  = model.ShortDescription;
            newProject.FullDetails       = model.FullDetails;
            newProject.ProgressStatus    = model.ProgressStatus;
            newProject.WorkorSideProject = model.WorkorSideProject;
            newProject.Size       = model.Size;
            newProject.ImgURI     = model.ImgURI;
            newProject.GithubLink = model.GithubLink;

            _projectData.Add(newProject);

            return(View("AddSuccess", newProject));
        }