Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,CityId,Requirements,Description,PhoneNumber,Email,Site,Facebook,Adress")] Company company, IFormFile Image, Guid?Id)
        {
            var emp = _context.Employers.Include(e => e.Company).ThenInclude(c => c.City)
                      .Include(e => e.AccountUser).FirstOrDefault(e => e.Id == Id);

            //if (ModelState.IsValid)
            {
                company.Id = Guid.NewGuid();

                var files = HttpContext.Request.Form.Files;
                if (Image != null)
                {
                    string     name       = Image.FileName;
                    string     path       = $"/files/{name}";
                    string     serverPath = $"{_environment.WebRootPath}{path}";
                    FileStream fs         = new FileStream(serverPath, FileMode.Create,
                                                           FileAccess.Write);
                    await Image.CopyToAsync(fs);

                    fs.Close();
                    company.CompanyLogoUrl = path;
                }
                company.Employers.Add(emp);

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Id", company.CityId);
            return(View(company));
        }
        public async Task <IActionResult> Create([Bind("Id,LastName,Name,Surname,Sex,Birthday,CityId,Country,Region,Street,ApartmentNumber,PhoneNumber,Email,Skype,Facebook,FamilyStatusId, ChildrenId")] Search_Work.Models.ArreaDatabase.Candidate candidate, IFormFile Image)
        {
            if (ModelState.IsValid)
            {
                candidate.Id = Guid.NewGuid();

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

                    fs.Close();
                    candidate.Avatar = path;
                }

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

                return(RedirectToAction(nameof(Edit), new { id = candidate.Id }));
            }
            ViewData["CityId"]         = new SelectList(_context.Cities, "Id", "Name", candidate.CityId);
            ViewData["FamilyStatusId"] = new SelectList(_context.FamilyStatuses, "Id", "Name");
            ViewData["ChildrenId"]     = new SelectList(_context.Childrens, "Id", "Name");
            return(View(candidate));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] City city)
        {
            if (ModelState.IsValid)
            {
                city.Id = Guid.NewGuid();
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CompanyLogoUrl,CityId,Requirements,Description,PhoneNumber,Email,Site,Facebook,Adress")] Company company)
        {
            if (ModelState.IsValid)
            {
                company.Id = Guid.NewGuid();
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Id", company.CityId);
            return(View(company));
        }