public async Task <bool> updateTeacher(UpdateTeacher teacher)
        {
            /* var user = await UserManager.FindByIdAsync(teacher.Id);
             * var newPassword = UserManager.PasswordHasher.HashPassword(user, teacher.Password);
             * user.PasswordHash = newPassword;
             * user.Name = teacher.Name;
             * user.LastName = teacher.LastName;
             * user.School = teacher.School;
             * user.Email = teacher.Email;
             * user.Degree = teacher.Degree;
             * user.City = teacher.City;
             * var res = await UserManager.UpdateAsync(user);
             *
             * if (res.Succeeded)
             * {
             *   return true;
             * }
             * else
             * {
             *   return false;
             * }*/
            await repository.updateTeacher(teacher);

            await repository.SaveChangesAsync();

            return(true);
        }
Esempio n. 2
0
        public IHttpActionResult Update(UpdateTeacher model)
        {
            IHttpActionResult httpActionResult;
            ErrorsModel       errors = new ErrorsModel();

            Teachers gv = this._db.Teachers.FirstOrDefault(x => x.Id == model.Id);

            if (gv == null)
            {
                errors.Add("Mã giảng viên không tồn tại hoặc rỗng");

                httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors);
            }
            else
            {
                gv.Code = model.Code ?? model.Code;
                gv.Name = model.Name ?? model.Name;

                this._db.Entry(gv).State = System.Data.Entity.EntityState.Modified;

                this._db.SaveChanges();

                httpActionResult = Ok(new TeacherModel(gv));
            }

            return(httpActionResult);
        }
Esempio n. 3
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            using (var db = new SpecialtySelectorDbContext())
            {
                var teacher = db.Teachers.Find(id);
                var adminId = this.User.Identity.GetUserId();

                if (teacher == null)
                {
                    return(HttpNotFound());
                }

                var teacherViewModel = new UpdateTeacher
                {
                    Id            = teacher.Id,
                    FirstName     = teacher.FirstName,
                    SecondName    = teacher.SecondName,
                    LastName      = teacher.LastName,
                    TeacherInfo   = teacher.TeacherInfo,
                    Degree        = teacher.Degree,
                    AcademicTitle = teacher.AcademicTitle,
                    AdminId       = adminId,
                    Subjects      = teacher.Subjects
                };

                return(View(teacherViewModel));
            }
        }
Esempio n. 4
0
        public async Task updateTeacher(UpdateTeacher teacher)
        {
            var teacherEntity = await PIDBContext.Users.SingleAsync(u => u.Id == teacher.Id);

            teacherEntity.UpdateDate = DateTime.Now;
            teacherEntity.UserName   = teacher.UserName;
            teacherEntity.Email      = teacher.Email;
            teacherEntity.Name       = teacher.Name;
            teacherEntity.LastName   = teacher.LastName;
            teacherEntity.Degree     = teacher.Degree;
            teacherEntity.City       = teacher.City;
            teacherEntity.Uid        = teacher.Uid;
        }
Esempio n. 5
0
        public async Task <IActionResult> updateTeacher([FromBody] UpdateTeacher teacher)
        {
            if (ModelState.IsValid)
            {
                var result = await service.updateTeacher(teacher);

                if (result)
                {
                    return(Ok(Tuple.Create(result)));
                }
            }

            return(BadRequest("Algo salio mal en la peticion"));
        }
        public async Task <object> Put(UpdateTeacher request)
        {
            var response = new BaseResponse();
            Expression <Func <Teacher, bool> > keySelector = x => x.Id == request.Id;
            var entity = await _teacherService.GetById(keySelector : keySelector);

            request.ToEntity(entity);
            var result = await _teacherService.Update(entity);

            response.Success    = true;
            response.Message    = "Update teacher success";
            response.StatusCode = (int)HttpStatusCode.OK;
            response.Results    = result;
            return(response);
        }
Esempio n. 7
0
        public ActionResult <Teacher> Put(int id, [FromBody] UpdateTeacher updateTeacher)
        {
            var teacher = DbContext.Teachers.FirstOrDefault(c => c.ID == id);

            if (teacher == null)
            {
                return(NotFound("Sorry, no teacher was found with that ID."));
            }
            else
            {
                teacher.FirstName     = updateTeacher.FirstName;
                teacher.LastName      = updateTeacher.LastName;
                teacher.LastUpdatedOn = DateTime.Now;
                teacher.EmailAddress  = updateTeacher.EmailAddress;
                DbContext.SaveChanges();
                return(teacher);
            }
        }
Esempio n. 8
0
        public ActionResult Update(UpdateTeacher updateTeacher)
        {
            if (ModelState.IsValid && updateTeacher != null)
            {
                using (var db = new SpecialtySelectorDbContext())
                {
                    var teachers = db.Teachers.
                                   Find(updateTeacher.Id);
                    var adminId = this.User.Identity.GetUserId();
                    var subnew  = new List <Subject>();

                    if (updateTeacher.Subject != null)
                    {
                        foreach (var kvp in updateTeacher.Subject)
                        {
                            var asd = db.Subjects.FirstOrDefault(x => x.Id == kvp);
                            subnew.Add(asd);
                        }
                    }

                    teachers.AdminId       = adminId;
                    teachers.FirstName     = updateTeacher.FirstName;
                    teachers.SecondName    = updateTeacher.SecondName;
                    teachers.LastName      = updateTeacher.LastName;
                    teachers.TeacherInfo   = updateTeacher.TeacherInfo;
                    teachers.Degree        = updateTeacher.Degree;
                    teachers.AcademicTitle = updateTeacher.AcademicTitle;
                    teachers.FiredOn       = updateTeacher.FiredOn;
                    teachers.Subjects      = subnew;

                    db.SaveChanges();
                }

                return(RedirectToAction("Details", new { id = updateTeacher.Id }));
            }

            return(View(updateTeacher));
        }
 public static void MapDtoToEntity(this UpdateTeacher source, IEntity entity)
 {
     source.GetType().GetProperties().Each(x => Console.WriteLine(x));
 }