Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,StartingDate,Salary,VacationDays,Experience,OfficeId")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OfficeId"] = new SelectList(_context.Offices, "Id", "City", employee.OfficeId);
            return(View(employee));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,CompanyId,Country,City,Street,StreetNumber,IsHeadquarters")] Office office)
        {
            if (ModelState.IsValid)
            {
                _context.Add(office);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", office.CompanyId);
            return(View(office));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,CreationDate")] Company company)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(company);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(company));
        }