示例#1
0
 public RegisteredStudent Update(UpdateStudent updateRegistry)
 {
     using (SchoolDataContext schoolContext = new SchoolDataContext())
     {
         var studentToUpdate = updateRegistry.ToEntity();
         schoolContext.Students.Attach(studentToUpdate);
         //schoolContext.Entry(studentToUpdate).Property(x => x.Name).IsModified = true;
         schoolContext.Entry(studentToUpdate).State = System.Data.Entity.EntityState.Modified;
         schoolContext.SaveChanges();
         return(studentToUpdate.toDTO());
     }
 }
示例#2
0
        public async Task <object> Put(UpdateStudent request)
        {
            var response = new BaseResponse();
            Expression <Func <Student, bool> > keySelector = x => x.Id == request.Id;
            var entity = await _studentService.GetById(keySelector : keySelector);

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

            response.Success    = true;
            response.Message    = "Update student success";
            response.StatusCode = (int)HttpStatusCode.OK;
            response.Results    = result.ConvertTo <StudentDto>();
            return(response);
        }