예제 #1
0
        public async Task <IActionResult> AddSkillSubmit(AddFileVm model)
        {
            var prAll = dbContext.Projects
                        .Include(p => p.Attachments)
                        .ToList();
            var updatePr = prAll.FirstOrDefault(p => p.Id == model.Id);
            var newskill = new Skill()
            {
                Id   = Guid.NewGuid(),
                Name = model.Tytle,
                // ProjectId = updatePr.Id
            };


            if (updatePr.Skills == null)
            {
                updatePr.Skills = new List <Skill>()
                {
                };
            }
            dbContext.Skills.Add(newskill);
            updatePr.Skills.Add(newskill);

            await dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(EditProject), new { Id = updatePr.Id }));
        }
예제 #2
0
        public IActionResult AddSkill(Guid prId)
        {
            var prAll = dbContext.Projects
                        .Include(p => p.ProjectType)
                        .Include(p => p.Attachments)
                        .Include(p => p.Skills)
                        .ToList();
            var updatePr = prAll.FirstOrDefault(p => p.Id == prId);

            var model = new AddFileVm()
            {
                Id    = updatePr.Id,
                Tytle = updatePr.Title,
            };

            return(View("/Views/Projects/AddSkill.cshtml", model));
        }
예제 #3
0
        public async Task <IActionResult> UploadFileSubmitAsync(AddFileVm model, IFormFile File)
        {
            var prAll = dbContext.Projects
                        .Include(p => p.Attachments)
                        .ToList();
            var updatePr = prAll.FirstOrDefault(p => p.Id == model.Id);

            if (File != null)
            {
                string     name       = File.FileName;
                string     path       = $"/files/{name}";
                string     serverPath = $"{this.environment.WebRootPath}{path}";
                FileStream fs         = new FileStream(serverPath, FileMode.Create,
                                                       FileAccess.Write);
                await File.CopyToAsync(fs);

                fs.Close();

                var newFile = new DbFile()
                {
                    Id         = Guid.NewGuid(),
                    File       = path,
                    FileName   = name,
                    DateCreate = DateTime.Now
                };

                dbContext.DbFiles.Add(newFile);
                dbContext.SaveChanges();


                updatePr.Attachments.Add(newFile);
                updatePr.Updated = DateTime.Now;
                dbContext.Update(updatePr);

                await dbContext.SaveChangesAsync();
            }



            return(RedirectToAction(nameof(EditProject), new { Id = updatePr.Id }));
        }