Ejemplo n.º 1
0
        public List <LecturerEntity> CreateFromExcel(byte[] data)
        {
            List <LecturerEntity> lecturerEntities = new List <LecturerEntity>();

            if (data != null)
            {
                List <LecturerExcelModel> LecturerExcelModels = ConvertToIEnumrable <LecturerExcelModel>(data).ToList();

                foreach (var lecturerExcelModel in LecturerExcelModels.Where(lem => lem.Name != null))
                {
                    var userEntity = new UserEntity();
                    userEntity.Password = lecturerExcelModel.Password.Trim();
                    userEntity.Username = lecturerExcelModel.Username.Trim();
                    UserService.Create(userEntity);

                    var users = context.Users.Where(u => u.Username == userEntity.Username).ToList();
                    if (users.Count > 1)
                    {
                        throw new BadRequestException("Lecture was existed, username: " + userEntity.Username);
                    }
                    var user = users.FirstOrDefault();
                    user.Role = 4;
                    context.SaveChanges();
                    //Create User
                    var newLecturerEntity = new LecturerEntity();
                    newLecturerEntity    = lecturerExcelModel.ToEntity(newLecturerEntity);
                    newLecturerEntity.Id = user.Id;
                    var newLecturer = new Lecturer(newLecturerEntity);
                    context.Lecturers.Add(newLecturer);
                    context.SaveChanges();
                    lecturerEntities.Add(new LecturerEntity(newLecturer));
                }
            }
            return(lecturerEntities);
        }
Ejemplo n.º 2
0
        public LecturerEntity Create(LecturerExcelModel lecturerExcelModel)
        {
            var userEntity = new UserEntity();

            userEntity.Password = lecturerExcelModel.Password;
            userEntity.Username = lecturerExcelModel.Username.Trim();
            UserService.Create(userEntity);
            var users = context.Users.Where(u => u.Username == userEntity.Username).ToList();

            if (users.Count > 1)
            {
                throw new BadRequestException("Lecture was existed!");
            }
            var user = users.FirstOrDefault();

            user.Role = 4;
            context.SaveChanges();
            //Create User
            var newLecturerEntity = new LecturerEntity();

            newLecturerEntity    = lecturerExcelModel.ToEntity(newLecturerEntity);
            newLecturerEntity.Id = user.Id;
            var newLecturer = new Lecturer(newLecturerEntity);

            context.Lecturers.Add(newLecturer);
            context.SaveChanges();
            return(newLecturerEntity);
        }
        private void lecture_data_grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //datagrid datagrid = sender as datagrid;
            //datarowview datarowview = datagrid.selecteditem as datarowview;


            //emp_id_txtbx.Text = dataRowView["EmployeeId"].ToString();
            //name_txtbx.Text = dataRowView["Name"].ToString();
            //faculty_txtbx.Text = dataRowView["Faculty"].ToString();
            //dept_txtbx.Text = dataRowView["Department"].ToString();
            //center_combobx.Text = dataRowView["Center"].ToString();
            //building_txtbx.Text = dataRowView["Building"].ToString();
            //level_txtbx.Text = dataRowView["Level"].ToString();
            //rank_txtbx.Text = dataRowView["Rank"].ToString();
            updateMode            = true;
            delete_btn_.IsEnabled = true;
            DataGrid       dataGrid = (DataGrid)sender;
            LecturerEntity lecturer = dataGrid.SelectedItem as LecturerEntity;

            if (lecturer != null)
            {
                emp_id_txtbx.Text       = lecturer.EmployeeId.ToString();
                name_txtbx.Text         = lecturer.Name;
                faculty_combobx.Text    = lecturer.Faculty;
                department_combobx.Text = lecturer.Department;
                center_combobx.Text     = lecturer.Center;
                building_combobx.Text   = lecturer.Building;
                level_combobx.Text      = lecturer.Level.ToString();
                rank_txtbx.Text         = lecturer.Rank.ToString();
                emp_id_txtbx.IsEnabled  = false;
            }
        }
 public void SaveData(LecturerEntity lecturer)
 {
     using (IDbConnection con = new SQLiteConnection(AppData.ConnectionString))
     {
         try{
             con.Execute("INSERT INTO Lecturer (EmployeeId, Name, Faculty, Department, Center, Building, Level, Rank) values (@EmployeeId, @Name, @Faculty, @Department, @Center, @Building, @Level, @Rank)", lecturer);
         } catch (Exception e)
         {
             MessageBox.Show(e.Message);
         }
     }
 }
Ejemplo n.º 5
0
 public Lecturer(LecturerEntity lecturerEntity) : base(lecturerEntity)
 {
     if (lecturerEntity.Classes != null)
     {
         this.Classes = new HashSet <Class>();
         foreach (var classEntity in lecturerEntity.Classes)
         {
             classEntity.LecturerId = this.Id;
             this.Classes.Add(new Class(classEntity));
         }
     }
 }
 public void UpdateData(LecturerEntity lecturer)
 {
     using (IDbConnection con = new SQLiteConnection(AppData.ConnectionString))
     {
         try
         {
             con.Execute("UPDATE Lecturer SET Name=@Name, Faculty=@Faculty, Department=@Department, Center=@Center, Building=@Building, Level=@Level, Rank=@Rank WHERE EmployeeId=@EmployeeId", lecturer);
         }
         catch (Exception e)
         {
             MessageBox.Show(e.Message);
         }
     }
 }
 private void update_btn__Click(object sender, RoutedEventArgs e)
 {
     try
     {
         lecturer = CreateLecturerEntity();
         _lecturerViewModel.UpdateLecturerData(lecturer);
         lecturer_data_grid.ItemsSource = _lecturerViewModel.LoadLecturerData();
         ClearAll();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private LecturerEntity CreateLecturerEntity()
 {
     lecturer = new LecturerEntity {
         EmployeeId = int.Parse(emp_id_txtbx.Text),
         Name       = name_txtbx.Text,
         Faculty    = faculty_combobx.Text,
         Department = department_combobx.Text,
         Center     = center_combobx.Text,
         Building   = building_combobx.Text,
         Level      = int.Parse(level_combobx.Text),
         Rank       = double.Parse(rank_txtbx.Text)
     };
     return(lecturer);
 }
Ejemplo n.º 9
0
        public LecturerEntity Update(UserEntity userEntity, Guid LecturerId, LecturerEntity lecturerEntity)
        {
            Lecturer Lecturer = context.Lecturers.Include(c => c.Classes).FirstOrDefault(c => c.Id == LecturerId);

            if (Lecturer == null)
            {
                throw new NotFoundException("Class not found!");
            }
            Lecturer updateLecturer = new Lecturer(lecturerEntity);

            updateLecturer.CopyTo(Lecturer);
            context.SaveChanges();
            List <Class> Classes = context.Classes.Where(sc => sc.LecturerId == LecturerId).ToList();
            List <Class> Insert, Update, Delete;
            List <Class> newClasses = lecturerEntity.Classes == null
                ? new List <Class>()
                : lecturerEntity.Classes.Select(c => new Class(c)).ToList();

            Common <Class> .Split(newClasses, Classes, out Insert, out Update, out Delete);

            if (Insert != null)
            {
                foreach (var c in Insert)
                {
                    c.Id         = Guid.NewGuid();
                    c.LecturerId = Lecturer.Id;
                    Classes.Add(c);
                }
            }
            if (Update != null)
            {
                foreach (var c in Update)
                {
                    var curClass = Classes.FirstOrDefault(s => s.Id == c.Id);
                    Common <Class> .Copy(c, curClass);
                }
            }
            if (Delete != null)
            {
                foreach (var c in Delete)
                {
                    var deleteClass = Classes.FirstOrDefault(s => c.Id == s.Id);
                    Classes.Remove(deleteClass);
                }
            }
            context.SaveChanges();

            return(new LecturerEntity(Lecturer, Lecturer.Classes));
        }
Ejemplo n.º 10
0
 public void UpdateLecturerData(LecturerEntity lecturer)
 {
     _lecturerData.UpdateData(lecturer);
 }
Ejemplo n.º 11
0
 public void SaveLecturerData(LecturerEntity lecturer)
 {
     _lecturerData.SaveData(lecturer);
 }
Ejemplo n.º 12
0
 public LecturerEntity Update([FromBody] LecturerEntity LecturerEntity, [FromRoute] Guid LecturerId)
 {
     return(LecturerService.Update(UserEntity, LecturerId, LecturerEntity));
 }