Example #1
0
        public IActionResult ModifyStudent(string index, ModifyStudentRequest req)
        {
            var context = new uniContext();
            var changed = from Student s in context.Student where s.Indexnumber == index select s;

            foreach (Student s in changed)
            {
                if (req.Firstname != null)
                {
                    s.Firstname = req.Firstname;
                }
                if (req.Lastname != null)
                {
                    s.Lastname = req.Lastname;
                }
                if (req.Birthdate != null)
                {
                    try
                    {
                        var newDate = DateTime.ParseExact(req.Birthdate, "dd.MM.yyyy", CultureInfo.InvariantCulture);
                        s.Birthdate = newDate;
                    }
                    catch (Exception e)
                    {
                        return(BadRequest("Incorrect date format. Correct format: dd.MM.yyyy"));
                    }
                }
            }
            context.SaveChanges();
            return(Created("api/students/" + index, changed.First()));
        }
Example #2
0
        public ModifyStudentResponse ModifyStudent(string index, ModifyStudentRequest request)
        {
            var db = new s18985Context();

            var s = db.Student.Where(d => d.IndexNumber == index).FirstOrDefault();

            if (s == null)
            {
                return(null);
            }
            else
            {
                s.FirstName = request.FirstName;
                s.LastName  = request.LastName;
                s.BirthDate = request.BirthDate;
                db.SaveChanges();

                ModifyStudentResponse response = new ModifyStudentResponse();
                response.IndexNumber = s.IndexNumber;
                response.FirstName   = s.FirstName;
                response.LastName    = s.LastName;
                response.BirthDate   = s.BirthDate;

                return(response);
            }
        }
Example #3
0
 public void ModifyStudent(ModifyStudentRequest modifyStudentRequest)
 {
     _context.Students.Where(s => s.IdStudent == modifyStudentRequest.IdStudent).ToList().ForEach(s =>
     {
         s.FirstName = modifyStudentRequest.FirstName;
         s.LastName  = modifyStudentRequest.LastName;
     });
 }
Example #4
0
        public void ModifyStudent(ModifyStudentRequest request)
        {
            var student = _context.Student.Find(request.IndexNumber);

            student.FirstName = request.FirstName;
            student.LastName  = request.LastName;
            student.BirthDate = request.BirthDate;
            _context.SaveChanges();
        }
Example #5
0
 public IActionResult ModifyStudent(ModifyStudentRequest request)
 {
     try
     {
         Student student = _service.ModifyStudent(request);
         return(Ok(student));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #6
0
 public IActionResult ModifyStudent(ModifyStudentRequest request)
 {
     try
     {
         var student = _service.ModifyStudent(request);
         return(Created("ModifyStudent", student));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #7
0
        public async Task <IActionResult> UpdateStudentAsync(ModifyStudentRequest msr)
        {
            int i = 0;

            i = await _db.ModifyStudentAsync(msr);

            if (i == -1)
            {
                return(NotFound("Student does not exist"));
            }
            return(Ok("Student updated"));
        }
Example #8
0
        public IActionResult ModifyStudent(string index, ModifyStudentRequest request)
        {
            var res = _service.ModifyStudent(index, request);

            if (res != null)
            {
                return(Ok(res));
            }
            else
            {
                return(NotFound("Nie ma takiego studenta"));
            }
        }
Example #9
0
        [Route("api/students/modifyStudent")] //zmień na student
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            var db = new _2019SBDContext();


            var s = new Student
            {
                IndexNumber = request.IndexNumber,
                FirstName   = request.FirstName,
                LastName    = request.LastName,
                BirthDate   = request.BirthDate
            };

            db.Attach(s);

            if (request.FirstName != null)
            {
                db.Entry(s).Property("FirstName").IsModified = true;
            }

            if (request.LastName != null)
            {
                db.Entry(s).Property("LastName").IsModified = true;
            }

            if (request.BirthDate != null)
            {
                db.Entry(s).Property("BirthDate").IsModified = true;
            }

            db.SaveChanges();
            var db2 = new _2019SBDContext();


            var res = db2.Student
                      .Where(d => d.IndexNumber == request.IndexNumber)
                      .FirstOrDefault();



            var response = new ModifyStudentResponse();

            response.IndexNumber = res.IndexNumber;
            response.FirstName   = res.FirstName;
            response.LastName    = res.LastName;
            response.BirthDate   = res.BirthDate;



            return(Ok(response));
        }
Example #10
0
        public Student ModifyStudent(ModifyStudentRequest request)
        {
            var student = _context.Student.Find(request.IndexNumber);

            if (student == null)
            {
                throw new Exception("no such student");
            }
            student.FirstName = request.FirstName;
            student.LastName  = request.LastName;
            student.BirthDate = request.Birthdate;
            _context.SaveChanges();
            return(student);
        }
Example #11
0
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            ModifyStudentResponse response;

            try
            {
                response = _dbService.ModifyStudent(request);
            }
            catch (Exception ex)
            {
                return(BadRequest("Something went wrong"));
            }
            return(Ok(response));
        }
Example #12
0
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            IActionResult response = Ok($"Successfully modified {request.IndexNumber}");

            try
            {
                _dbService.ModifyStudent(request);
            }
            catch (Exception e)
            {
                response = BadRequest(e);
            }
            return(response);
        }
Example #13
0
        public void ModifyStudent(ModifyStudentRequest request)
        {
            var st = new Student
            {
                IndexNumber  = request.IndexNumber,
                FirstName    = request.FirstName,
                LastName     = request.LastName,
                BirthDate    = request.BirthDate,
                IdEnrollment = request.IdEnrollment,
            };

            _dbContext.Attach(st);
            _dbContext.Entry(st).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }
Example #14
0
        [Route("api/students/deleteStudent")] //zmień na student
        public IActionResult DeleteStudent(ModifyStudentRequest request)
        {
            var db      = new _2019SBDContext();
            var student = new Student
            {
                IndexNumber = request.IndexNumber
            };

            db.Attach(student);
            db.Remove(student);


            db.SaveChanges();
            return(Ok(request.IndexNumber + " zostal usunięty"));
        }
Example #15
0
        public void ModifyStudent(ModifyStudentRequest request)
        {
            var s = new Student
            {
                IndexNumber  = request.indexNumber,
                FirstName    = request.firstName,
                LastName     = request.lastName,
                BirthDate    = request.birthDate,
                IdEnrollment = request.idEnrollment,
                Password     = request.password
            };

            _dbContext.Attach(s);
            _dbContext.Entry(s).State = EntityState.Modified;
            _dbContext.SaveChanges();
        }
Example #16
0
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            IActionResult response;

            try
            {
                _context.ModifyStudent(request);
                response = Ok("Pomyslnie zmodyfikowano studenta o indexie " + request.indexNumber);
            }
            catch (Exception exc)
            {
                response = BadRequest("Błąd przy modyfikowaniu studenta" + exc.StackTrace);
            }

            return(response);
        }
Example #17
0
        public async Task <IActionResult> ModifyStudent(ModifyStudentRequest request)
        {
            var student = _context.Student.FirstOrDefault(n => n.IndexNumber == request.IndexNumber);

            if (student == null)
            {
                return(new BadRequestResult());
            }

            student.FirstName    = request.FirstName;
            student.LastName     = request.LastName;
            student.BirthDate    = request.BirthDate;
            student.IdEnrollment = request.IdEnrollment;

            await _context.SaveChangesAsync();

            return(new OkObjectResult(student));
        }
Example #18
0
 public void ModifyStudent(ModifyStudentRequest request)
 {
     try
     {
         var student = (from s in _context.Student where s.IndexNumber == request.IndexNumber select s).Single();
         student.FirstName    = request?.FirstName ?? student.FirstName;
         student.LastName     = request?.LastName ?? student.LastName;
         student.BirthDate    = request?.BirthDate ?? student.BirthDate;
         student.IdEnrollment = request?.IdEnrollment ?? student.IdEnrollment;
         _context.SaveChanges();
     }
     catch (Exception e)
     {
         throw new Exception(
                   $"Couldn\'t update student {request.IndexNumber} due to: {e.StackTrace} {e.Message}"
                   );
     }
 }
        public Student ModifyStudent(ModifyStudentRequest request)
        {
            var student = _context.Student.FirstOrDefault(e => e.IndexNumber == request.IndexNumber);

            if (student == null)
            {
                throw new Exception("Nie ma takiego studenta");
            }

            student.IndexNumber  = request.IndexNumber;
            student.FirstName    = request.FirstName;
            student.LastName     = request.LastName;
            student.BirthDate    = request.BirthDate;
            student.IdEnrollment = request.IdEnrollment;

            _context.SaveChanges();

            return(student);
        }
        public ModifyStudentResponse ModifyStudent(ModifyStudentRequest request)
        {
            try
            {
                var student = _dbContext.Student.Where(s => s.IndexNumber == request.IndexNumber).Single();

                student.FirstName = request?.FirstName ?? student.FirstName;
                student.LastName  = request?.LastName ?? student.LastName;
                // student.IdEnrollment = request?.IdEnrollment ?? student.IdEnrollment; ------ Nie mozna zmienic bo klucz obcy i wyrzuca wyjatek
                student.BirthDate = request?.birthDate ?? student.BirthDate;
                student.Password  = request?.password ?? student.Password;

                _dbContext.SaveChanges();
            }
            catch (Exception exc)
            {
                throw exc;
            }

            /*    var student = new Student
             *  {
             *      FirstName = request.FirstName,
             *      LastName = request.LastName,
             *      IndexNumber = request.LastName,
             *      IdEnrollment = request.IdEnrollment,
             *      BirthDate = request.birthDate,
             *      Password = request.password
             *  };
             *  _dbContext.Attach(student);
             *  _dbContext.Entry(student).State = EntityState.Modified;
             *  _dbContext.SaveChanges();
             */
            return(new ModifyStudentResponse
            {
                FirstName = request.FirstName,
                LastName = request.LastName,
                IndexNumber = request.LastName,
                IdEnrollment = request.IdEnrollment,
                birthDate = request.birthDate
            });
        }
Example #21
0
        public async Task <int> ModifyStudentAsync(ModifyStudentRequest usr)
        {
            var exists = _studentContext.Student.Any(s => s.IndexNumber == usr.IndexNumber);

            if (!exists)
            {
                return(-1);
            }
            var st = new Student
            {
                IndexNumber  = usr.IndexNumber,
                FirstName    = usr.FirstName,
                LastName     = usr.LastName,
                BirthDate    = usr.BirthDate,
                IdEnrollment = usr.IdEnrollment,
                Password     = usr.Password
            };

            _studentContext.Attach(st);
            _studentContext.Entry(st).State = EntityState.Modified;
            await _studentContext.SaveChangesAsync();

            return(0);
        }
Example #22
0
        public IActionResult ModifyStudent(ModifyStudentRequest request)
        {
            if (request == null || request.IndexNumber == null)
            {
                return(BadRequest("Brak danych wejściowych"));
            }

            var student = db.Student.Where(s => s.IndexNumber.Equals(request.IndexNumber)).ToList().First();

            if (student == null)
            {
                return(NotFound("Student with index: @index not found"));
            }

            if (request.FirstName != null)
            {
                student.FirstName = request.FirstName;
            }
            if (request.LastName != null)
            {
                student.LastName = request.LastName;
            }
            if (request.BirthDate != null)
            {
                student.BirthDate = request.BirthDate;
            }
            if (request.IdEnrollment != 0)
            {
                student.IdEnrollment = request.IdEnrollment;
            }

            db.Student.Update(student);

            db.SaveChanges();
            return(Ok());
        }
Example #23
0
 public IActionResult ModifyStudent(ModifyStudentRequest modifyStudentRequest)
 {
     return Ok(_dbService.ModifyStudent(modifyStudentRequest));
 }
Example #24
0
 public void ModifyStudent(ModifyStudentRequest request)
 {
     throw new NotImplementedException();
 }
Example #25
0
 public IActionResult ModifyStudent(ModifyStudentRequest request)
 {
     _service.ModifyStudent(request);
     return(Ok("Student's data was successfully modified"));
 }
Example #26
0
 public async Task <IActionResult> ModifyStudent(ModifyStudentRequest request)
 {
     return(await _service.ModifyStudent(request));
 }