コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Email,Title,Text,CreatedAt,State,PresentationId,ReplyToCommentId")] CommentModel commentModel)
        {
            if (ModelState.IsValid)
            {
                commentModel.CreatedAt = DateTime.Now;
                commentModel.State     = "Show";
                _context.Add(commentModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ReplyToCommentId"] = new SelectList(_context.CommentModel, "Id", "Name", commentModel.ReplyToCommentId);
            ViewData["PresentationId"]   = new SelectList(_context.PresentaionModel, "Id", "Name", commentModel.PresentationId);
            return(View(commentModel));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,DescriptionShort,DescriptionLong")] ProjectModel projectModel,
                                                 IFormFile imageFile,
                                                 [Bind("techIds")] int[] techIds)
        {
            if (ModelState.IsValid)
            {
                var UploadImage = new UploadImage(_env, _config);
                projectModel.Image = await UploadImage.Create(imageFile);

                if (techIds != null)
                {
                    foreach (int techId in techIds)
                    {
                        var tech = _context.TechModel.First(t => t.Id == techId);
                        if (tech != null)
                        {
                            projectModel.Teches.Add(tech);
                        }
                    }
                }
                _context.Add(projectModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(projectModel));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,ProjectId")] IssueModel issueModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(issueModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", issueModel.ProjectId);
            return(View(issueModel));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Image,DescriptionShort,DescriptionLong,EstimateTime,EstimatePrice,LastChange,ProjectId")] PresentaionModel presentaionModel,
                                                 IFormFile imageFile)
        {
            if (ModelState.IsValid)
            {
                string fullFilePath    = null;
                string fileName        = null;
                string uploadDirectory = _uploadDirectory;
                System.IO.Directory.CreateDirectory(uploadDirectory);

                if (imageFile != null && imageFile.Length > 0)
                {
                    string fileExt = Path.GetExtension(imageFile.FileName).ToLowerInvariant();

                    if (string.IsNullOrEmpty(fileExt) || !_permittedExtensions.Contains(fileExt))
                    {
                        Message = "Error : Invalid File Extension";
                        ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId);
                        return(View());
                    }

                    if (imageFile.Length > _fileSizeLimit)
                    {
                        Message = "Error : File max size must be 10MB";
                        ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId);
                        return(View());
                    }

                    do
                    {
                        fileName     = Guid.NewGuid().ToString() + fileExt;
                        fullFilePath = string.Format(@"{0}\{1}", uploadDirectory, fileName);
                    } while (System.IO.File.Exists(fullFilePath));

                    using (var stream = System.IO.File.Create(fullFilePath))
                    {
                        await imageFile.CopyToAsync(stream);
                    }

                    presentaionModel.Image = string.Format(@"{0}\{1}", @"images\upload", fileName);
                }

                presentaionModel.LastChange = DateTime.Now;
                _context.Add(presentaionModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.ProjectModel, "Id", "Name", presentaionModel.ProjectId);
            return(View(presentaionModel));
        }
コード例 #5
0
ファイル: TechController.cs プロジェクト: somidmmehr/Dotteam
        public async Task <IActionResult> Create([Bind("Id,Name,Image,Description")] TechModel techModel,
                                                 IFormFile imageFile)
        {
            if (ModelState.IsValid)
            {
                var UploadImage = new UploadImage(_env, _config);
                techModel.Image = await UploadImage.Create(imageFile);

                _context.Add(techModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(techModel));
        }