Esempio n. 1
0
        public async Task <IActionResult> Create(IFormFile PhotoImg, [Bind("PositionId,Bio,TopMember,Id,FirstName,LastName,Email,Phone")] Member member)
        {
            if (ModelState.IsValid)
            {
                // Image upload --- rewrite with good structure
                if (PhotoImg != null)
                {
                    long size = PhotoImg.Length;
                    // full path to file in temp location
                    var filePath = Path.Combine("wwwroot/uploads/profileimgs/", PhotoImg.FileName);
                    if (PhotoImg.Length > 0)
                    {
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await PhotoImg.CopyToAsync(stream);
                        }
                    }

                    //Database save
                    member.PhotoImg = PhotoImg.FileName;
                }
                _context.Add(member);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["PositionId"] = new SelectList(_context.Positions, "Id", "Title", member.PositionId);

            return(View(member));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Bio,SocialLink,VolunteerOpportunityId,FirstName,LastName,Email,Phone")] Volunteer volunteer)
        {
            if (ModelState.IsValid)
            {
                volunteer.ApplicationDate = DateTime.Now;
                _context.Add(volunteer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            ViewData["OpportunityId"] = new SelectList(_context.VolunteerOpportunities, "Id", "Title", volunteer.VolunteerOpportunityId);
            return(View(volunteer));
        }
        public async Task <IActionResult> Create(ICollection <IFormFile> images, IFormFile MainImg, [Bind("Id,Featured,MemberId,Title,VolunteerOpp,InvestOpp,StartDate,FinishDate,ShortDesc,Description,Location,LatLng,SocialLinks,Status")] Project project)
        {
            if (ModelState.IsValid)
            {
                // Image upload --- rewrite with good structure
                if (MainImg != null)
                {
                    long size = MainImg.Length;
                    // full path to file in temp location
                    var filePath = Path.Combine("wwwroot/uploads/", MainImg.FileName);
                    if (MainImg.Length > 0)
                    {
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await MainImg.CopyToAsync(stream);
                        }
                    }

                    //Database save
                    project.MainImg = MainImg.FileName;
                }

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

                if (project.VolunteerOpp)
                {
                    VolunteerOpportunity task = new VolunteerOpportunity();
                    task.JobType   = "Help";
                    task.ProjectId = project.Id;
                    task.Title     = project.Title + " hepl!";
                    _context.Add(task);
                    await _context.SaveChangesAsync();
                }

                if (images != null)
                {
                    foreach (var img in images)
                    {
                        var filePath = Path.Combine("wwwroot/uploads/", img.FileName);

                        if (img.Length > 0)
                        {
                            using (var fileStream = new FileStream(filePath, FileMode.Create))
                            {
                                await img.CopyToAsync(fileStream);

                                Image tmpImg = new Image();
                                tmpImg.Name      = "Image";
                                tmpImg.Path      = img.FileName;
                                tmpImg.ProjectId = project.Id;
                                _context.Images.Add(tmpImg);
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["MemberId"] = new SelectList(_context.Members, "Id", "LastName", project.MemberId);
            return(View(project));
        }