示例#1
0
        public async Task <ActionResult <StudentDto> > Put([FromBody] StudentDto studentDto, CancellationToken token)
        {
            var entity = _mapper.Map <Student>(studentDto);

            _context.Update(entity);
            await _context.SaveChangesAsync();

            return(studentDto);
        }
        public async Task <IActionResult> Edit(int id, [Bind("StudentId,StudentNo,StudentName,StudentSurname,StudentEmail,StudentTelNo,DepartmentId")] Student student)
        {
            if (id != student.StudentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.StudentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
示例#3
0
        public async Task <IActionResult> Edit(int id, [Bind("id,first_name,last_name")] Students students)
        {
            if (id != students.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(students);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentsExists(students.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,DepartmentName")] Department department)
        {
            if (id != department.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(department);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DepartmentExists(department.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
示例#5
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Name,NormalizedName,ConcurrencyStamp")] AspNetRole aspNetRole)
        {
            if (id != aspNetRole.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aspNetRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspNetRoleExists(aspNetRole.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(aspNetRole));
        }
示例#6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nume,Prenume,An,Facultate,Camera,Etaj,Sex,TaxaAchitata")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
示例#7
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] AspNetUser aspNetUser)
        {
            if (id != aspNetUser.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(aspNetUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AspNetUserExists(aspNetUser.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(aspNetUser));
        }
示例#8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,StuID,Department")] Student student)
        {
            if (id != student.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(student);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentExists(student.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Department"] = new SelectList(_context.Departments, "Id", "Name", student.DepartmentId);
            return(View(student));
        }
示例#9
0
        public static void UpdateNoTracking()
        {
            Department update = new Department {
                DepartmentId = 3, Name = "Katedra za informacione tehnologije"
            };

            //update.Name = "Katedra za informacione tehnologije";
            context.Update(update);
            context.SaveChanges();
        }
示例#10
0
        public static void UpdateSubjectWithDepartmentNoTracking()
        {
            List <Subject> subjectsWithDepartment = context.Subjects.Include(s => s.Department).ToList();

            using StudentsContext newcontext = new StudentsContext();
            Subject s = subjectsWithDepartment[0];

            s.Department.Name = "Department Update No Tracking";
            newcontext.Update(s);
            newcontext.SaveChanges();
        }
示例#11
0
        public static void AddSubjectItemToSubjectNoTracking()
        {
            Subject s = context.Subjects.First();

            s.Items.Add(new SubjectItem {
                Name = "Vezbe 10"
            });
            using StudentsContext newcontext = new StudentsContext();
            newcontext.Update(s);                                                                  //posto slab objekat ima slozen kljuc, on nije generisan i onda je za njega state modified
            newcontext.Entry(s.Items.Single(i => i.Name == "Vezbe 10")).State = EntityState.Added; //moramo da promenimo state na update
            newcontext.SaveChanges();
        }
示例#12
0
        public IActionResult Put(int id)
        {
            MeetingRoom meetingRoom = db.MeetingRooms
                                      .FirstOrDefault(x => x.Id == id);

            if (meetingRoom == null)
            {
                return(NotFound("Meeting room not found!"));
            }

            db.Update(meetingRoom);
            db.SaveChanges();

            return(Ok(meetingRoom));
        }
示例#13
0
        public IActionResult Put(int id)
        {
            Student student = db.GetStudents.FirstOrDefault(x => x.Id == id);

            if (!db.GetStudents.Any(x => x.Id == id))
            {
                return(NotFound());
            }

            student.IndexNumber = "S7894";

            db.Update(student);
            db.SaveChanges();
            return(Ok(student));
        }
示例#14
0
        public IActionResult Put([FromBody] MeetingRoom meetingRoom)
        {
            if (meetingRoom == null)
            {
                return(BadRequest());
            }

            if (db.MeetingRooms.Any(x => x.Id == meetingRoom.Id))
            {
                return(NotFound());
            }

            db.Update(meetingRoom);
            db.SaveChanges();

            return(Ok(meetingRoom));
        }