Exemple #1
0
        public T Save()
        {
            var entity       = State as IEntity;
            var identityUser = State as IdentityUser;

            if (entity != null)
            {
                if (Context.Entry(entity).State != EntityState.Modified)
                {
                    Context.Add(entity);
                }
            }
            else if (identityUser != null)
            {
                Context.Add(identityUser);
            }
            else if (State is IdentityRole)
            {
                Context.Add(State);
            }
            else
            {
                throw new BuilderSaveException($"State {State} has to be an Entity or IdentityUser.");
            }

            Context.SaveChanges();
            return((T)this);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Lastname")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Hours,TeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TeacherId"] = new SelectList(_context.Teachers, "Id", "Id", course.TeacherId);
            return(View(course));
        }