Example #1
0
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = System.Data.Entity.EntityState.Modified;
 }
 public void Attach(T entity)
 {
     dbSet.Attach(entity);
 }
 private void MockAttach(IDbSet <T> dbset)
 {
     dbset.Attach(Arg.Any <T>()).ReturnsForAnyArgs(a => AddItem(a[0] as T));
 }
 public void Update(T obj)
 {
     table.Attach(obj);
     Context.Entry(obj).State = EntityState.Modified;
 }
Example #5
0
 public void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
     //dataContext.SaveChanges();
 }
Example #6
0
 public void Update(TEntity entity)
 {
     set.Attach(entity);
     context.Entry(entity).State = EntityState.Modified;
 }
Example #7
0
 public void Update(T entity)
 {
     DbSet.Attach(entity);
     ctx.Entry(entity).State = EntityState.Modified;
 }
Example #8
0
 public void Update(T entity)
 {
     dbSet.Attach(entity);//EF syntax,
     _context.Entry(entity).State = EntityState.Modified;
 }
 public virtual void Update(T Entity)
 {
     DBSet.Attach(Entity);
     DataContext.Entry(Entity).State = EntityState.Modified;
 }
 public void Update(TEntity entity)
 {
     _dbSet.Attach(entity);
 }
Example #11
0
        public void Update(T entity)
        {
            var type = typeof(T);

            switch (type.Name)
            {
            case "Indicator":
                var indicator = entity as Indicator;
                if (indicator != null)
                {
                    var item = DataContext.Indicators.FirstOrDefault(f => f.Id == indicator.Id);
                    item.Name             = indicator.Name;
                    item.LastModifiedDate = DateTime.Now;
                    item.ObjectType       = DataContext.ObjectTypes.FirstOrDefault(f => f.Id == indicator.ObjectType.Id);
                    item.Ratio            = DataContext.Ratios.FirstOrDefault(f => f.Id == indicator.Ratio.Id);
                    item.Scores           = indicator.Scores;
                    _dataContext.Entry(item.Ratio).State      = EntityState.Unchanged;
                    _dataContext.Entry(item.ObjectType).State = EntityState.Unchanged;
                    DataContext.Entry(item).State             = EntityState.Modified;
                    //_dbSet.Attach(indicator as T);
                }
                break;

            case "Score":
                var score = entity as Score;
                if (score != null)
                {
                    _dataContext.Entry(score.Indicator).State = EntityState.Unchanged;
                    _dataContext.Entry(score).State           = EntityState.Modified;
                    _dbSet.Attach(score as T);
                }
                break;

            case "ProfessorScore":
                var professorScore = entity as ProfessorScore;
                if (professorScore != null)
                {
                    var item = DataContext.ProfessorScores.FirstOrDefault(f => f.Id == professorScore.Id);
                    item.Term         = DataContext.Terms.Where(w => w.Id == professorScore.Term.Id).FirstOrDefault();
                    item.Score        = DataContext.Scores.Where(w => w.Id == professorScore.Score.Id).FirstOrDefault();
                    item.Professor    = DataContext.Professors.Where(w => w.Id == professorScore.Professor.Id).FirstOrDefault();
                    item.CurrentScore = professorScore.CurrentScore;
                    _dataContext.Entry(item.Term).State      = EntityState.Unchanged;
                    _dataContext.Entry(item.Professor).State = EntityState.Unchanged;
                    _dataContext.Entry(item.Score).State     = EntityState.Unchanged;
                    _dataContext.Entry(item).State           = EntityState.Modified;
                    //_dbSet.Attach(item as T);
                }
                break;

            case "Professor":
                var professor = entity as Professor;
                if (professor != null)
                {
                    var item = DataContext.Professors.FirstOrDefault(f => f.Id == professor.Id);
                    item.AcademicDegree               = professor.AcademicDegree;
                    item.Address                      = professor.Address;
                    item.AverageGradeEvaluation       = professor.AverageGradeEvaluation;
                    item.Description                  = professor.Description;
                    item.EducationPlaceUniversityRank = professor.EducationPlaceUniversityRank;
                    item.Email = professor.Email;
                    item.EntryAndExitStatus         = professor.EntryAndExitStatus;
                    item.ExamQuestionsProvideTimely = professor.ExamQuestionsProvideTimely;
                    item.Family              = professor.Family;
                    item.FatherName          = professor.FatherName;
                    item.Gender              = professor.Gender;
                    item.GroupMangerComments = professor.GroupMangerComments;
                    item.InPersonSession     = professor.InPersonSession;
                    item.IsActive            = professor.IsActive;
                    item.LastModifiedDate    = DateTime.Now;
                    item.Mobile              = professor.Mobile;
                    item.Name                  = professor.Name;
                    item.NationalCode          = professor.NationalCode;
                    item.OnlineSession         = professor.OnlineSession;
                    item.OthersSession         = professor.OthersSession;
                    item.ProfessorAccessStatus = professor.ProfessorAccessStatus;
                    item.ScientificRank        = professor.ScientificRank;
                    item.ScoresAnnounceTimely  = professor.ScoresAnnounceTimely;
                    item.Status                = professor.Status;
                    item.TeachingExperience    = professor.TeachingExperience;
                    item.UniversityStudyPlace  = professor.UniversityStudyPlace;
                    item.UniversityWorkPlace   = professor.UniversityWorkPlace;

                    // //_dataContext.Entry(professor.Colleges).State = EntityState.Unchanged;
                    // _dataContext.Entry(professor.EducationalClasses).State = EntityState.Unchanged;
                    //// _dataContext.Entry(professor.EducationalGroups).State = EntityState.Unchanged;
                    // _dataContext.Entry(professor.ProfessorScores).State = EntityState.Unchanged;
                    _dataContext.Entry(item).State = EntityState.Modified;
                    //_dbSet.Attach(professor as T);
                }
                break;

            case "EducationalGroupScore":
                var educationalGroupScore = entity as EducationalGroupScore;
                if (educationalGroupScore != null)
                {
                    var item = DataContext.EducationalGroupScores.FirstOrDefault(f => f.Id == educationalGroupScore.Id);
                    item.Term             = DataContext.Terms.FirstOrDefault(w => w.Id == educationalGroupScore.Term.Id);
                    item.Score            = DataContext.Scores.FirstOrDefault(w => w.Id == educationalGroupScore.Score.Id);
                    item.EducationalGroup = DataContext.EducationalGroups.FirstOrDefault(w => w.Id == educationalGroupScore.EducationalGroup.Id);
                    item.CurrentScore     = educationalGroupScore.CurrentScore;
                    _dataContext.Entry(item.Term).State             = EntityState.Unchanged;
                    _dataContext.Entry(item.Score).State            = EntityState.Unchanged;
                    _dataContext.Entry(item.EducationalGroup).State = EntityState.Unchanged;
                    DataContext.Entry(item).State = EntityState.Modified;
                    //_dbSet.Attach(educationalGroupScore as T);
                }
                break;

            case "EducationalGroup":
                var educationalGroup = entity as EducationalGroup;
                if (educationalGroup != null)
                {
                    var item = DataContext.EducationalGroups.FirstOrDefault(f => f.Id == educationalGroup.Id);
                    item.College = DataContext.Colleges.FirstOrDefault(f => f.Id == educationalGroup.College.Id);
                    item.EducationalGroupScores            = DataContext.EducationalGroupScores.Where(w => w.EducationalGroup.Id == educationalGroup.Id).ToList();
                    item.InTimePresentCurriculum           = educationalGroup.InTimePresentCurriculum;
                    _dataContext.Entry(item.College).State = EntityState.Unchanged;
                    //_dataContext.Entry(item.EducationalGroupScores).State = EntityState.Unchanged;
                    DataContext.Entry(item).State = EntityState.Modified;
                    //_dbSet.Attach(educationalGroup as T);
                }
                break;

            case "EducationalClass":
                var educationalClass = entity as EducationalClass;
                if (educationalClass != null)
                {
                    _dataContext.Entry(educationalClass.Professor).State = EntityState.Unchanged;
                    // _dataContext.Entry(educationalClass.EducationalGroups).State = EntityState.Unchanged;
                    // _dataContext.Entry(educationalClass.Colleges).State = EntityState.Unchanged;
                    DataContext.Entry(educationalClass).State = EntityState.Modified;
                    //_dbSet.Attach(educationalClass as T);
                }
                break;

            case "CollegeScore":
                var collegeScore = entity as CollegeScore;
                if (collegeScore != null)
                {
                    _dataContext.Entry(collegeScore.Term).State    = EntityState.Unchanged;
                    _dataContext.Entry(collegeScore.Score).State   = EntityState.Unchanged;
                    _dataContext.Entry(collegeScore.College).State = EntityState.Unchanged;
                    DataContext.Entry(collegeScore).State          = EntityState.Modified;
                    _dbSet.Attach(collegeScore as T);
                }
                break;

            case "UniversityLevelMapping":
                var universityLevelMapping = entity as UniversityLevelMapping;
                if (universityLevelMapping != null)
                {
                    var item = DataContext.UniversityLevelMappings.FirstOrDefault(f => f.Id == universityLevelMapping.Id);
                    item.Score            = DataContext.Scores.FirstOrDefault(f => f.Id == universityLevelMapping.Score.Id);
                    item.IsActive         = universityLevelMapping.IsActive;
                    item.LastModifiedDate = DateTime.Now;
                    item.UniversityName   = universityLevelMapping.UniversityName;
                    _dataContext.Entry(item.Score).State = EntityState.Unchanged;
                    DataContext.Entry(item).State        = EntityState.Modified;
                }
                break;

            case "User":
                var user = entity as User;
                if (user != null)
                {
                    var item = DataContext.Users.FirstOrDefault(f => f.ID == user.ID);
                    if (user.College != null)
                    {
                        item.College = DataContext.Colleges.FirstOrDefault(f => f.Id == user.College.Id);
                        //_dataContext.Entry(item.College).State = EntityState.Unchanged;
                    }
                    //if (user.EducationalGroup != null)
                    //{
                    //    item.EducationalGroup = DataContext.EducationalGroups.FirstOrDefault(f => f.Id == user.EducationalGroup.Id);
                    //    //_dataContext.Entry(item.EducationalGroup).State = EntityState.Unchanged;
                    //}
                    item.FirstName = user.FirstName;
                    item.LastName  = user.LastName;
                    item.Password  = user.Password;
                    item.Username  = user.Username;
                    _dataContext.Entry(item).State = EntityState.Modified;
                }
                break;

            case "Schedule":
                var schedule = entity as Schedule;
                if (schedule != null)
                {
                    var item = DataContext.Schedules.FirstOrDefault(f => f.Id == schedule.Id);
                    item.ActionMethod              = schedule.ActionMethod;
                    item.Description               = schedule.Description;
                    item.IsActive                  = schedule.IsActive;
                    item.LastModifiedDate          = DateTime.Now;
                    item.Name                      = schedule.Name;
                    item.TimeLapse                 = schedule.TimeLapse;
                    item.TimeLapseMeasurement      = schedule.TimeLapseMeasurement;
                    item.LastRunDate               = schedule.LastRunDate;
                    item.NextRunDate               = schedule.NextRunDate;
                    _dataContext.Entry(item).State = EntityState.Modified;
                }
                break;

            case "EvaluationQuestion":
                var evaluationQuestion = entity as EvaluationQuestion;
                if (evaluationQuestion != null)
                {
                    var item = DataContext.EvaluationQuestion.FirstOrDefault(x => x.Id == evaluationQuestion.Id);
                    item.Term                      = DataContext.Terms.FirstOrDefault(w => w.Id == evaluationQuestion.Term.Id);
                    item.EvaluationType            = DataContext.EvaluationType.FirstOrDefault(w => w.Id == evaluationQuestion.EvaluationType.Id);
                    item.IsLastQuestion            = evaluationQuestion.IsLastQuestion;
                    item.ParentId                  = evaluationQuestion.ParentId;
                    item.Text                      = evaluationQuestion.Text;
                    _dataContext.Entry(item).State = EntityState.Modified;
                }
                break;

            case "EvaluationAnswer":
                var evaluationAnswer = entity as EvaluationAnswer;
                if (evaluationAnswer != null)
                {
                    evaluationAnswer.Question = DataContext.EvaluationQuestion.FirstOrDefault(x => x.Id == evaluationAnswer.Question.Id);
                    _dataContext.Entry(evaluationAnswer.Question).State = EntityState.Unchanged;
                    _dataContext.Entry(evaluationAnswer).State          = EntityState.Added;
                    try
                    {
                        _dataContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                break;
            }

            var ss = _dataContext.SaveChanges();
        }
Example #12
0
 public void Update(T obj)
 {
     table.Attach(obj);
     _context.Entry(obj).State = EntityState.Modified;
     _context.SaveChanges();
 }
 public override void Update(T entity)
 {
     _dbset.Attach(entity);
     DataContext.Entry(entity).State = EntityState.Modified;
     SaveChanges();
 }
Example #14
0
 public void Attach(TEntity entity)
 {
     DBSet.Attach(entity);
 }
Example #15
0
 public virtual void Add(T entity)
 {
     _dbSet.Attach(entity);
     _dataContext.Entry(entity).State = EntityState.Added;
 }
 public virtual void Update(TEntity entity)
 {
     dbSet.Attach(entity);
     DbContext.Entry(entity).State = EntityState.Modified;
 }
 public void Update(T obj, string userName)
 {
     table.Attach(obj);
     _context.Entry(obj).State = EntityState.Modified;
     _context.SaveChanges(userName);
 }
Example #18
0
 public void Update(T Entity)
 {
     dbset.Attach(Entity);
     ctx.Entry <T>(Entity).State = EntityState.Modified;
 }
 public virtual void Update(TEntity entity)
 {
     DbSet.Attach(entity);
 }
Example #20
0
 public virtual RepositoryBase <T> Update(T entity)
 {
     dbSet.Attach(entity);
     DataContext.Entry(entity).State = EntityState.Modified;
     return(this);
 }
Example #21
0
 public virtual void Update(T entity)
 {
     _dbSet.Attach(entity);
     _dataContext.Entry(entity).State = EntityState.Modified;
 }
Example #22
0
 public void Update(T entity)
 {
     dbSet.Attach(entity);
     dbContext.Entry(entity).State = EntityState.Modified;
 }