public ActionResult Edit(Student student, HttpPostedFileBase imageFile)
        {
            using (var ms = new MemoryStream())
            {
                imageFile.InputStream.CopyTo(ms);
                student.Picture = ms.ToArray();
            }

            db.Entry(student).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> PutStudent([FromRoute] Guid id, [FromBody] Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutTblDrejtimet(int id, TblDrejtimet tblDrejtimet)
        {
            if (id != tblDrejtimet.DrejtimetId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #4
0
        public ActionResult Edit(Student student, int[] selectedCourses)
        {
            Student newStudent = db.Students.Find(student.Id);

            newStudent.Name    = student.Name;
            newStudent.Surname = student.Surname;

            newStudent.Courses.Clear();
            if (selectedCourses != null)
            {
                //получаем выбранные курсы
                foreach (var c in db.Courses.Where(co => selectedCourses.Contains(co.Id)))
                {
                    newStudent.Courses.Add(c);
                }
            }

            db.Entry(newStudent).State = EntityState.Modified;
            db.SaveChanges();
            SearchHelper.AddToIndex(new List <Student>()
            {
                student
            });
            return(RedirectToAction("Index"));
        }
        public IHttpActionResult PutStudent(int id, Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != student.Id)
            {
                return(BadRequest());
            }

            db.Entry(student).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutTblLendet(int id, TblLendet tblLendet)
        {
            if (id != tblLendet.LendetId)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.TblLendet
                .Include(i => i.Drejtimi)
                .FirstOrDefaultAsync(i => i.DrejtimiId == id);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TblLendetExists(id))
                {
                    return(NotFound("Lenda nuk u gjet!"));
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #7
0
        public ActionResult Add(List <Student> students)
        {
            Student curStudent;

            foreach (var student in students)
            {
                curStudent = db.Students.Find(student);

                if (curStudent == null)
                {
                    return(HttpNotFound("Не найдена книга по ID " + student.Id));
                }

                db.Entry(curStudent).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
            return(View("Index"));
        }
Beispiel #8
0
 public ActionResult Edit([Bind(Include = "Id,Name,LastName,BirthDate,Email,City")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
 public ActionResult Edit([Bind(Include = "id,FirstName,LastName,UserName,Password,Email")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
Beispiel #10
0
        public async Task <ActionResult> Edit([Bind(Include = "COURSE_ID,NAME")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Entry(course).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(course));
        }
        public async Task <ActionResult> Edit([Bind(Include = "STUDENT_ID,NAME,LASTNAME,AGE,COURSE_ID")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Entry(student).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.COURSE_ID = new SelectList(db.Course, "COURSE_ID", "NAME", student.COURSE_ID);
            return(View(student));
        }
 public ActionResult Edit([Bind(Include = "Id,CourseId,StudentId,Durtation,StartDate,EndDate,HolidayStartDay,HolidayEndDate")] CourseList courseList)
 {
     if (ModelState.IsValid)
     {
         db.Entry(courseList).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId  = new SelectList(db.Corses, "Id", "CourseName", courseList.CourseId);
     ViewBag.StudentId = new SelectList(db.Students, "Id", "FullName", courseList.StudentId);
     return(View(courseList));
 }
Beispiel #13
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();
        }
Beispiel #14
0
        public async Task <ActionResult> Put(int id, [FromBody] Student entity)
        {
            if (id != entity.StudentId)
            {
                return(BadRequest());
            }

            _db.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _db.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #15
0
        public static void UpdateOnlyDepartmentNoTracking()
        {
            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.Attach(s);
            newcontext.Entry(s.Department).State = EntityState.Modified;
            newcontext.SaveChanges();
        }
 public ActionResult Edit(Student student)
 {
     db.Entry(student).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }