Ejemplo n.º 1
0
        public void TaoNguoiDung(long ma, string ho, string ten, int gioitinh, DateTime ngaysinh,
                                 string diachi, string sdt, string email, string vaitro)
        {
            try
            {
                if (vaitro == "SinhVien")
                {
                    Data.Models.SinhVien sinhVienExist = _context.SinhVien.Find(ma);
                    if (sinhVienExist == null)
                    {
                        Data.Models.SinhVien sinhVien = new Data.Models.SinhVien()
                        {
                            Mssv     = ma,
                            Ho       = ho,
                            Ten      = ten,
                            GioiTinh = gioitinh,
                            NgaySinh = ngaysinh,
                            DiaChi   = diachi,
                            Sdt      = sdt,
                            Email    = email,
                            Status   = 1
                        };
                        _context.SinhVien.Add(sinhVien);
                        _context.SaveChanges();
                    }
                }
                else if (vaitro == "GVHD")
                {
                    GiangVien giangVienExist = _context.GiangVien.Find(ma);
                    if (giangVienExist == null)
                    {
                        GiangVien giangVien = new GiangVien()
                        {
                            Id       = ma,
                            Ho       = ho,
                            Ten      = ten,
                            GioiTinh = gioitinh,
                            NgaySinh = ngaysinh,
                            DiaChi   = diachi,
                            Sdt      = sdt,
                            Email    = email,
                            Status   = 1
                        };
                        _context.GiangVien.Add(giangVien);
                        _context.SaveChanges();
                    }
                }
                else
                {
                    QuanLy quanLyExist = _context.QuanLy.Find(ma);
                    if (quanLyExist == null)
                    {
                        QuanLy quanLy = new QuanLy()
                        {
                            Id       = ma,
                            Ho       = ho,
                            Ten      = ten,
                            GioiTinh = gioitinh,
                            NgaySinh = ngaysinh,
                            DiaChi   = diachi,
                            Sdt      = sdt,
                            Email    = email,
                            Status   = 1
                        };
                        _context.QuanLy.Add(quanLy);
                        _context.SaveChanges();
                    }
                }

                var user = _userManager.FindByNameAsync(ma.ToString()).Result;
                if (user == null)
                {
                    user = new AppUser
                    {
                        UserName  = ma.ToString(),
                        IsEnabled = true
                    };
                    var result = _userManager.CreateAsync(user, "Pass123$").Result;
                    if (!result.Succeeded)
                    {
                        throw new Exception(result.Errors.First().Description);
                    }
                    result = _userManager.AddToRoleAsync(user, vaitro).Result;
                    if (!result.Succeeded)
                    {
                        throw new Exception(result.Errors.First().Description);
                    }

                    result = _userManager.AddClaimsAsync(user, new Claim[] {
                        new Claim("Name", ho + " " + ten)
                    }).Result;
                    if (!result.Succeeded)
                    {
                        throw new Exception(result.Errors.First().Description);
                    }
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> LoadData()
        {
            try
            {
                var draw = HttpContext.Request.Form["draw"].FirstOrDefault();

                // Skip number of Rows count
                var start = Request.Form["start"].FirstOrDefault();

                // Paging Length 10,20
                var length = Request.Form["length"].FirstOrDefault();

                // Sort Column Name
                var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();

                // Sort Column Direction (asc, desc)
                var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();

                // Search Value from (Search box)
                var searchValue = Request.Form["search[value]"].FirstOrDefault();

                //Paging Size (10, 20, 50,100)
                int pageSize = length != null?Convert.ToInt32(length) : 0;

                int skip = start != null?Convert.ToInt32(start) : 0;

                int recordsTotal = 0;

                // getting all Customer data
                Data.Models.SinhVien sinhVien = await _serviceSV.GetById(long.Parse(User.Identity.Name));

                List <NhomSinhVien> nhomSv = sinhVien.NhomSinhVien.ToList();
                var query = nhomSv.Select(x => x.IddeTaiNavigation);
                //Mapping
                var list = _mapper.Map <IEnumerable <DeTaiNghienCuu>, IEnumerable <DeTaiNghienCuuViewModel> >(query);
                //foreach (var item in list)
                //{
                //    //var nhomSinhVien = await _serviceNhomSV.GetAll(x=>x.Idnhom == item.Idnhom);
                //    //foreach(var x in nhomSinhVien)
                //    //{
                //    //    item.Mssv = item.Mssv + x.IdsinhVien.ToString() + '   ';
                //    //}
                //    if (int.Parse(item.TinhTrangDeTai) == (int)StatusDeTai.DanhGiaLai)
                //        item.TinhTrangDeTai = "Chờ xét duyệt/đánh giá";
                //    else if (int.Parse(item.TinhTrangDeTai) == (int)StatusDeTai.HoanThanh)
                //        item.TinhTrangDeTai = "Hoàn thành";
                //    else if (int.Parse(item.TinhTrangDeTai) == (int)StatusDeTai.DaDangKy)
                //        item.TinhTrangDeTai = "Đã đăng ký";
                //    else
                //        item.TinhTrangDeTai = "Đang thực hiện";
                //}

                //Sorting
                if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortColumnDirection))
                {
                    PropertyDescriptor prop = TypeDescriptor.GetProperties(typeof(DeTaiNghienCuuViewModel)).Find(sortColumn, false);
                    if (sortColumnDirection.Equals("asc"))
                    {
                        list = list.OrderBy(x => prop.GetValue(x));
                    }
                    else
                    {
                        list = list.OrderByDescending(x => prop.GetValue(x));
                    }
                }

                //Search
                if (!string.IsNullOrEmpty(searchValue))
                {
                    list = list.Where(x => x.Id.ToString().Contains(searchValue) ||
                                      x.TenDeTai.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                      x.TinhTrangDeTai.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0 ||
                                      x.MoTa.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0
                                      //|| x.HoTenGVHD.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0
                                      //|| x.Email.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0
                                      || x.TenTep.IndexOf(searchValue, StringComparison.OrdinalIgnoreCase) >= 0
                                      );
                }

                //total number of rows counts
                recordsTotal = list.Count();
                //Paging
                var data = list.Skip(skip).Take(pageSize).ToList();
                //Returning Json Data
                return(Json(new
                {
                    draw = draw,
                    recordsFiltered = recordsTotal,
                    recordsTotal = recordsTotal,
                    data = data
                }));
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task <ThongTinTaiKhoan> LayThongTin(string nguoidung, long id)
        {
            if (nguoidung == "GVHD")
            {
                GiangVien giangVien = await _context.GiangVien.FindAsync(id);

                if (giangVien != null)
                {
                    ThongTinTaiKhoan thongTinTaiKhoan = new ThongTinTaiKhoan()
                    {
                        TenTaiKhoan = giangVien.Id.ToString(),
                        HoTen       = giangVien.Ho + " " + giangVien.Ten,
                        Sdt         = giangVien.Sdt,
                        Email       = giangVien.Email,
                        VaiTro      = "Giảng viên",
                        TrangThai   = false
                    };
                    return(thongTinTaiKhoan);
                }
                return(null);
            }
            else if (nguoidung == "SinhVien")
            {
                Data.Models.SinhVien sinhVien = await _context.SinhVien.FindAsync(id);

                if (sinhVien != null)
                {
                    ThongTinTaiKhoan thongTinTaiKhoan = new ThongTinTaiKhoan()
                    {
                        TenTaiKhoan = sinhVien.Mssv.ToString(),
                        HoTen       = sinhVien.Ho + " " + sinhVien.Ten,
                        Sdt         = sinhVien.Sdt,
                        Email       = sinhVien.Email,
                        VaiTro      = "Sinh viên",
                        TrangThai   = false
                    };
                    return(thongTinTaiKhoan);
                }
                return(null);
            }
            else if (nguoidung == "QuanLy")
            {
                QuanLy quanLy = await _context.QuanLy.FindAsync(id);

                if (quanLy != null)
                {
                    ThongTinTaiKhoan thongTinTaiKhoan = new ThongTinTaiKhoan()
                    {
                        TenTaiKhoan = quanLy.Id.ToString(),
                        HoTen       = quanLy.Ho + " " + quanLy.Ten,
                        Sdt         = quanLy.Sdt,
                        Email       = quanLy.Email,
                        VaiTro      = "Quản lý",
                        TrangThai   = false
                    };
                    return(thongTinTaiKhoan);
                }
                return(null);
            }
            else
            {
                QuanLy quanLy = await _context.QuanLy.FindAsync(id);

                if (quanLy != null)
                {
                    ThongTinTaiKhoan thongTinTaiKhoan = new ThongTinTaiKhoan()
                    {
                        TenTaiKhoan = quanLy.Id.ToString(),
                        HoTen       = quanLy.Ho + " " + quanLy.Ten,
                        Sdt         = quanLy.Sdt,
                        Email       = quanLy.Email,
                        VaiTro      = "Quản trị",
                        TrangThai   = false
                    };
                    return(thongTinTaiKhoan);
                }
                return(null);
            }
        }