Ejemplo n.º 1
0
        private async void SaveEducationsMethod()
        {
            if (IsEducationValid())
            {
                using (var _database = new ITManagerEntities())
                {
                    var userEducations = (await _database.Users.Where(u => u.Id == User.Id)
                                          .Include(u => u.Educations)
                                          .FirstOrDefaultAsync()).Educations;

                    // Removing and changing educations
                    foreach (var userEducation in userEducations.ToList())
                    {
                        var _userEducation = Educations.FirstOrDefault(l => l.Id == userEducation.Id);
                        // If exists in local collection, change data
                        if (_userEducation != null)
                        {
                            userEducation.StartDate  = _userEducation.StartDate;
                            userEducation.EndDate    = _userEducation.EndDate;
                            userEducation.Faculty    = _userEducation.Faculty;
                            userEducation.Speciality = _userEducation.Speciality;
                            userEducation.University = _userEducation.University;
                        }
                        // If not exists in local collection - remove.
                        else
                        {
                            _database.Educations.Remove(userEducation);
                        }
                    }

                    // Adding new education
                    foreach (var newEducation in Educations.Where(l => l.Id == 0))
                    {
                        userEducations.Add(new Education
                        {
                            StartDate  = newEducation.StartDate,
                            EndDate    = newEducation.EndDate,
                            Faculty    = newEducation.Faculty,
                            Speciality = newEducation.Speciality,
                            University = newEducation.University,
                            UserId     = User.Id
                        });
                    }

                    IsEducationsChecked = false;
                    User.Educations     = (await _database.Users.Where(u => u.Id == User.Id).FirstOrDefaultAsync())?.Educations;

                    await _database.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 2
0
 public List <Education> GetEducations()
 {
     return(Educations.Where(a => a.IsDeleted == false).ToList());
 }