Пример #1
0
        public async Task <IActionResult> PutCustomer(int id, Customer customer)
        {
            if (id != customer.Id)
            {
                return(BadRequest());
            }

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <ActionResult <Customer> > Create(Customer customer)
        {
            _context.Customer.Add(customer);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("DepartmentId,DepartmentTitle")] Departments departments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(departments);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(departments));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("JobId,JobTitle")] Jobs jobs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(jobs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(jobs));
        }
Пример #5
0
        public async Task <ActionResult> Create([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("PersonelId,FirstName,LastName,Salary,JobId,DeparmentId")] Employees employees)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employees);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DeparmentId"] = new SelectList(_context.Departments, "DepartmentId", "DepartmentId", employees.DeparmentId);
            ViewData["JobId"]       = new SelectList(_context.Jobs, "JobId", "JobId", employees.JobId);
            return(View(employees));
        }
Пример #7
0
        [ValidateAntiForgeryToken] //Wenn Create(Get-Methode) und Create (Post-Methode), den selben Namen haben
        // Muss ValidateAntiForgeryToken mit angegeben werden -> ValidateAntiForgeryToken hilft gegenüber CrossSiteAttacks
        public async Task <IActionResult> Create(Person person)
        {
            //ModelState.AddModelError("PersonenObj", "Kombination der Wert im Objekt, machen das Objekt unverndbar");

            //serverseitige Validierung
            if (ModelState.IsValid)
            {
                _context.Persons.Add(person);
                await _context.SaveChangesAsync();

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

            return(View(person));
        }
Пример #8
0
        public async Task <IActionResult> Execute(PersonDBContext _context, Person person)
        {
            _context.Person.Add(person);
            await _context.SaveChangesAsync();

            return(new NoContentResult());
        }
Пример #9
0
 private static void AddUsers(IList <User> users)
 {
     foreach (User user in users)
     {
         using (PersonDBContext fctxt = new PersonDBContext())
         {
             Console.WriteLine(user.ToString());
             fctxt.Users.AddAsync(user);
             fctxt.Entry(user).State = EntityState.Added;
             fctxt.SaveChangesAsync();
         }
     }
 }
Пример #10
0
 private static void AddPersons(IList <Person> persons)
 {
     foreach (Person person in persons)
     {
         using (PersonDBContext fctxt = new PersonDBContext())
         {
             Console.WriteLine(person.ToString());
             fctxt.Persons.AddAsync(person);
             fctxt.Entry(person).State = EntityState.Added;
             fctxt.SaveChangesAsync();
         }
     }
 }
        public async Task <IActionResult> Execute(PersonDBContext _context, long id)
        {
            var person = await _context.Person.FindAsync(id);

            if (person == null)
            {
                return(new NotFoundResult());
            }

            _context.Person.Remove(person);
            await _context.SaveChangesAsync();

            return(new NoContentResult());
        }
Пример #12
0
        public ActionResult Delete([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var employee = _context.Employees.FirstOrDefault(m => m.PersonelId == id);

            if (employee == null)
            {
                return(NotFound());
            }

            _context.Employees.Remove(employee);
            _context.SaveChangesAsync();

            return(Ok());
        }
 public async Task <IActionResult> Execute(PersonDBContext _context, Person person)
 {
     _context.Entry(person).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!_context.Person.Any(e => e.Id == person.Id))
         {
             return(new NotFoundResult());
         }
         else
         {
             throw;
         }
     }
     return(new NoContentResult());
 }
Пример #14
0
 public async Task Commit()
 {
     await _dBContext.SaveChangesAsync();
 }
Пример #15
0
        public async Task AddPersonAsync(Person person)
        {
            EntityEntry <Person> newlyAdded = await ctx.Persons.AddAsync(person);

            await ctx.SaveChangesAsync();
        }