예제 #1
0
        public void Delete(int id)
        {
            Article article = Read(id);

            _Context.Entry(article).State = EntityState.Deleted;
            _Context.SaveChanges();
        }
예제 #2
0
        public async Task <IActionResult> PutMyCourses(int id, MyCourses myCourses)
        {
            if (id != myCourses.itemID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #3
0
        public async Task SaveStreamAsync(int currentStudentId, int streamId)
        {
            var studentStream = _db.StudentStreams.FirstOrDefault(x => x.StudentId == currentStudentId);

            if (studentStream != null)
            {
                _db.StudentStreams.Remove(studentStream);
            }

            // If the added stream has been removed above in this method,
            // we change EntityState from "Deleted" to "Modified" for this stream
            var existingStudentStream = _db.StudentStreams.FirstOrDefault(s => s.StudentId == currentStudentId &&
                                                                          s.StreamId == streamId);

            if (existingStudentStream != null)
            {
                _db.Entry(existingStudentStream).State = EntityState.Modified;
            }
            else
            {
                //Create new StudentStream
                var newStudentStream = new StudentStream
                {
                    StudentId = currentStudentId,
                    StreamId  = streamId
                };
                _db.StudentStreams.Add(newStudentStream);
            }
        }
예제 #4
0
        public IActionResult Edit(Profile model)
        {
            model.TimeEdited = DateTime.Now;

            _db.Entry(model).State = EntityState.Modified;
            _db.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
예제 #5
0
        public async Task SaveSkillsAsync(int currentStudentId, string[] skills)
        {
            //Delete all student skills, if they are exist
            var studentSkills = _db.StudentSkills.Where(s => s.StudentId == currentStudentId).ToList();

            if (studentSkills.Count() != 0)
            {
                foreach (var stud in studentSkills)
                {
                    _db.StudentSkills.Remove(stud);
                }
            }

            //Add skill for current student
            foreach (var skill in skills)
            {
                var existingSkill = _db.Skills.FirstOrDefault(s => s.Name == skill);

                if (existingSkill != null)
                {
                    // If the added skill has been removed above in this method,
                    // we change EntityState from "Deleted" to "Modified" for this skill
                    var existingStudentSkill = studentSkills.FirstOrDefault(s => s.SkillId == existingSkill.Id &&
                                                                            s.StudentId == currentStudentId);
                    if (existingStudentSkill != null)
                    {
                        _db.Entry(existingStudentSkill).State = EntityState.Modified;
                    }
                    else
                    {
                        //If Skills are exist, add new record about Student and its skills
                        StudentSkill studentSkill = new StudentSkill
                        {
                            SkillId   = existingSkill.Id,
                            StudentId = currentStudentId,
                        };

                        _db.StudentSkills.Add(studentSkill);
                    }
                }
                //If skill is added by user, add new skill to table Skill and add new record about Student and its skills
                else
                {
                    var Skill = new Skill
                    {
                        Name = skill
                    };
                    _db.Skills.Add(Skill);

                    StudentSkill studentSkill = new StudentSkill
                    {
                        SkillId   = Skill.Id,
                        StudentId = currentStudentId,
                    };
                    _db.StudentSkills.Add(studentSkill);
                }
            }
        }
예제 #6
0
        public async Task SaveForeignLanguagesAsync(int resumeId, Dictionary <int, int> languageLevelIdsByLanguageIds)
        {
            //if there are foreign languages for current CV, to delete them
            var languages = _db.ForeignLanguages.Where(s => s.ResumeId == resumeId).ToList();

            if (languages.Count() != 0)
            {
                foreach (var lang in languages)
                {
                    _db.ForeignLanguages.Remove(lang);
                }
            }
            foreach (var languageItem in languageLevelIdsByLanguageIds)
            {
                //If the added foreign language has been removed above in this method,
                //we change EntityState from "Deleted" to "Modified" for this foreign language
                var existingForeignLanguage = languages.FirstOrDefault(l => l.ResumeId == resumeId &&
                                                                       l.LanguageId == languageItem.Key &&
                                                                       l.LanguageLevelId == languageItem.Value);
                if (existingForeignLanguage != null)
                {
                    _db.Entry(existingForeignLanguage).State = EntityState.Modified;
                }
                else
                {
                    ForeignLanguage foreignLanguage = new ForeignLanguage
                    {
                        ResumeId        = resumeId,
                        LanguageId      = languageItem.Key,
                        LanguageLevelId = languageItem.Value
                    };

                    _db.ForeignLanguages.Add(foreignLanguage);
                }
            }
        }
예제 #7
0
 public IActionResult Edit(Models.User model)
 {
     _db.Entry(model).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction(nameof(Index)));
 }