// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (this.ProjectImage != null)
            {
                var ImageName    = FileUploads.GetFileName(this.ProjectImage.FileName);
                var uploadImages = Path.Combine(_hostEnvironment.WebRootPath, "ProjectImages");
                var imagePath    = Path.Combine(uploadImages, ImageName);
                this.ProjectImage.CopyTo(new FileStream(imagePath, FileMode.Create));
                this.Project.ProjectImage = ImageName; // Set the file name
            }
            if (this.ProjectScope != null)
            {
                var document        = FileUploads.GetFileName(this.ProjectScope.FileName);
                var documentsFolder = Path.Combine(_hostEnvironment.WebRootPath, "documents");
                var documentPath    = Path.Combine(documentsFolder, document);
                this.ProjectScope.CopyTo(new FileStream(documentPath, FileMode.Create));
                this.Project.ProjectScope = document; // Set the file name
            }
            _context.Project.Add(Project);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Clients.Add(Client);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Project = await _context.Project.FindAsync(id);

            if (Project != null)
            {
                _context.Project.Remove(Project);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (this.ProjectImage != null)
            {
                var ImageName    = FileUploads.GetFileName(this.ProjectImage.FileName);
                var uploadImages = Path.Combine(_hostEnvironment.WebRootPath, "ProjectImages");
                var imagePath    = Path.Combine(uploadImages, ImageName);
                this.ProjectImage.CopyTo(new FileStream(imagePath, FileMode.Create));
                this.Project.ProjectImage = ImageName; // Set the file name
            }
            if (this.ProjectScope != null)
            {
                var document        = FileUploads.GetFileName(this.ProjectScope.FileName);
                var documentsFolder = Path.Combine(_hostEnvironment.WebRootPath, "documents");
                var documentPath    = Path.Combine(documentsFolder, document);
                this.ProjectScope.CopyTo(new FileStream(documentPath, FileMode.Create));
                this.Project.ProjectScope = document; // Set the file name
            }

            _context.Attach(Project).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectExists(Project.ProjectID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }