Beispiel #1
0
        public async Task <HuongNghienCuu> Create(HuongNghienCuuForCreateDto huongNghienCuu)
        {
            var danhSachHuongNghienCuu = await _context.DanhSachHuongNghienCuu.OrderByDescending(x => x.MaHuongNghienCuu).FirstOrDefaultAsync();

            var maHuongNghienCuu = 0;

            if (danhSachHuongNghienCuu == null)
            {
                maHuongNghienCuu = 0;
            }
            else
            {
                maHuongNghienCuu = danhSachHuongNghienCuu.MaHuongNghienCuu + 1;
            }
            var newHuongNghienCuu = new HuongNghienCuu
            {
                MaHuongNghienCuu  = maHuongNghienCuu,
                TenHuongNghienCuu = huongNghienCuu.TenHuongNghienCuu,
                ThoiGianTao       = DateTime.Now,
                ThoiGianCapNhat   = DateTime.Now,
                TrangThai         = 1
            };

            await _context.DanhSachHuongNghienCuu.AddAsync(newHuongNghienCuu);

            await _context.SaveChangesAsync();

            return(newHuongNghienCuu);
        }
Beispiel #2
0
        public async Task <ICollection <HuongNghienCuu> > CreateMultiple(ICollection <HuongNghienCuuForCreateMultipleDto> danhSachHuongNghienCuu)
        {
            ICollection <HuongNghienCuu> temp = new List <HuongNghienCuu>();

            for (int i = 0; i < danhSachHuongNghienCuu.Count; i++)
            {
                var huongNghienCuu = danhSachHuongNghienCuu.ElementAt(i);

                var newHuongNghienCuu = new HuongNghienCuu
                {
                    MaHuongNghienCuu  = huongNghienCuu.MaHuongNghienCuu,
                    TenHuongNghienCuu = huongNghienCuu.TenHuongNghienCuu,
                    ThoiGianTao       = huongNghienCuu.ThoiGianTao,
                    ThoiGianCapNhat   = huongNghienCuu.ThoiGianCapNhat,
                    TrangThai         = huongNghienCuu.TrangThai
                };

                temp.Add(newHuongNghienCuu);

                await _context.DanhSachHuongNghienCuu.AddAsync(newHuongNghienCuu);

                await _context.SaveChangesAsync();
            }

            return(temp);
        }
Beispiel #3
0
        private HuongNghienCuu GetHNCFromDataRow(DataRow row)
        {
            HuongNghienCuu s = new HuongNghienCuu();

            s.Ma_Huong_NC = row["Ma_Huong_NC"].ToString();
            s.Ten         = row["Ten"].ToString();
            s.ID_GVHD     = row["ID_GVHD"].ToString();
            return(s);
        }
Beispiel #4
0
        public HuongNghienCuu[] getAllHNC()
        {
            string    sqlCmd = "SELECT * FROM HuongNghienCuu";
            DataTable d      = DBHelper.DBExcuteQuery(sqlCmd);
            int       count  = d.Rows.Count;

            HuongNghienCuu[] results = new HuongNghienCuu[count];
            for (int i = 0; i < count; i++)
            {
                results[i] = GetHNCFromDataRow(d.Rows[i]);
            }

            return(results);
        }
Beispiel #5
0
        public async Task <HuongNghienCuu> UpdateById(int id, HuongNghienCuuForUpdateDto huongNghienCuu)
        {
            var oldRecord = await _context.DanhSachKhoa.AsNoTracking().FirstOrDefaultAsync(x => x.MaKhoa == id);

            var huongNghienCuuToUpdate = new HuongNghienCuu
            {
                MaHuongNghienCuu  = id,
                TenHuongNghienCuu = huongNghienCuu.TenHuongNghienCuu,
                ThoiGianTao       = oldRecord.ThoiGianTao,
                ThoiGianCapNhat   = DateTime.Now,
                TrangThai         = huongNghienCuu.TrangThai
            };

            _context.DanhSachHuongNghienCuu.Update(huongNghienCuuToUpdate);
            await _context.SaveChangesAsync();

            return(huongNghienCuuToUpdate);
        }