public async Task <ActionResult <IEnumerable <VB_QT_VanBanMoiSoHoa> > > r2AddQTChuyenChoPheDuyet(VB_QT_LuanChuyenVanBan vB_QT_LuanChuyenVanBan)
        {
            try
            {
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                var userNN = await _context.Sys_Dm_User.FindAsync(vB_QT_LuanChuyenVanBan.NguoiNhanId);

                var qtLuanChuyenVb = await _context.VB_QT_LuanChuyenVanBan.FindAsync(vB_QT_LuanChuyenVanBan.Id);

                qtLuanChuyenVb.NgayDoc  = DateTime.Now;
                qtLuanChuyenVb.DaDoc    = true;
                qtLuanChuyenVb.NgayXuLy = DateTime.Now;
                VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                    qtLuanChuyenVb.VbMoiSoHoaId, vB_QT_LuanChuyenVanBan.NguoiNhanId, vB_QT_LuanChuyenVanBan.TenNguoiNhan, userId, user.FullName,
                    vB_QT_LuanChuyenVanBan.TieuDe,
                    vB_QT_LuanChuyenVanBan.NoiDung, false,
                    vB_QT_LuanChuyenVanBan.HanXuLy, null,
                    vB_QT_LuanChuyenVanBan.TrangThaiXuLy,
                    vB_QT_LuanChuyenVanBan.MaLenh, null,
                    false, qtLuanChuyenVb.Id,
                    vB_QT_LuanChuyenVanBan.MenuGuiId,
                    vB_QT_LuanChuyenVanBan.MenuNhanId,
                    userNN.PositionName, user.PositionName, userNN.DepartmentName, user.DepartmentName);
                _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                Sys_QT_ThongBao obj = new Sys_QT_ThongBao();
                obj.MaLenh        = vB_QT_LuanChuyenVanBan.MaLenh;
                obj.QuyTrinhId    = 1;
                obj.TenNguoiGui   = user.FullName;
                obj.NguoiNhanId   = vB_QT_LuanChuyenVanBan.NguoiNhanId ?? 0;
                obj.NoiDung       = vB_QT_LuanChuyenVanBan.NoiDung;
                obj.NgayGui       = DateTime.Now;
                obj.DaDoc         = false;
                obj.NgayDoc       = null;
                obj.TrangThaiXuLy = vB_QT_LuanChuyenVanBan.TrangThaiXuLy;
                obj.RouterLink    = "/vanban/quytrinhvanban/vanbanchopheduyet";
                _context.Sys_QT_ThongBao.Add(obj);
                List <NguoiNhanThongBao> nhanThongBaos = new List <NguoiNhanThongBao>();
                NguoiNhanThongBao        nguoiNhan     = new NguoiNhanThongBao();
                nguoiNhan.NguoiNhanId = vB_QT_LuanChuyenVanBan.NguoiNhanId ?? 0;
                nhanThongBaos.Add(nguoiNhan);
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0, nguoiNhanTbs = nhanThongBaos }));
            }
            catch (Exception)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <IEnumerable <VB_QT_VanBanMoiSoHoa> > > r2AddQTPheDuyetTrinhKy(LuanChuyenVbDuyetTrinhKy luanChuyenVbXNHT)
        {
            try
            {
                List <NguoiNhanThongBao> nhanThongBaos = new List <NguoiNhanThongBao>();
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                var qtLuanChuyenVb = await _context.VB_QT_LuanChuyenVanBan.FindAsync(luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.Id);

                qtLuanChuyenVb.NgayXuLy = DateTime.Now;
                qtLuanChuyenVb.NgayDoc  = DateTime.Now;
                qtLuanChuyenVb.DaDoc    = true;

                var nguoiNhans = _context.VB_QT_LuanChuyenVanBan.Where(x => x.VbMoiSoHoaId == qtLuanChuyenVb.VbMoiSoHoaId).Select(a => new
                {
                    a.TenNguoiGui,
                    a.NguoiGuiId,
                    a.MaLenh
                }).Distinct().ToList();
                if (luanChuyenVbXNHT.UserXNHT.isNguoiGui == true)
                {
                    foreach (var item in nguoiNhans.Where(x => x.MaLenh == "VB_CHOTRINHKY" && x.NguoiGuiId != nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").NguoiGuiId))
                    {
                        var userNN = await _context.Sys_Dm_User.FindAsync(item.NguoiGuiId);

                        VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                            qtLuanChuyenVb.VbMoiSoHoaId, item.NguoiGuiId, item.TenNguoiGui, userId, user.FullName,
                            luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.TieuDe,
                            luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.NoiDung, false,
                            luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                            5,
                            "VB_NHANTHONGBAO", null, false,
                            qtLuanChuyenVb.Id,
                            luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MenuGuiId,
                            luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MenuNhanId,
                            userNN.PositionName, user.PositionName, userNN.DepartmentName, user.DepartmentName);
                        _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                        // thêm vào thông báo
                        Sys_QT_ThongBao obj = new Sys_QT_ThongBao();
                        obj.MaLenh        = "VB_NHANTHONGBAO";
                        obj.QuyTrinhId    = 1;
                        obj.TenNguoiGui   = user.FullName;
                        obj.NguoiNhanId   = item.NguoiGuiId;
                        obj.NoiDung       = luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.NoiDung;
                        obj.NgayGui       = DateTime.Now;
                        obj.DaDoc         = false;
                        obj.NgayDoc       = null;
                        obj.TrangThaiXuLy = 5;
                        obj.RouterLink    = "/vanban/quytrinhvanban/vanbandapheduyet";
                        NguoiNhanThongBao nguoiNhan = new NguoiNhanThongBao();
                        nguoiNhan.NguoiNhanId = item.NguoiGuiId;
                        nhanThongBaos.Add(nguoiNhan);
                        _context.Sys_QT_ThongBao.Add(obj);
                    }
                }
                var userNNN = await _context.Sys_Dm_User.FindAsync(nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").NguoiGuiId);

                VB_QT_LuanChuyenVanBan lcvb1 = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                    qtLuanChuyenVb.VbMoiSoHoaId, nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").NguoiGuiId, nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").TenNguoiGui, userId, user.FullName,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.TieuDe,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.NoiDung, false,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                    3,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MaLenh, null, false,
                    qtLuanChuyenVb.Id,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MenuGuiId,
                    luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MenuNhanId,
                    userNNN.PositionName, user.PositionName, userNNN.DepartmentName, user.DepartmentName);
                _context.VB_QT_LuanChuyenVanBan.Add(lcvb1);
                NguoiNhanThongBao nguoiNhan1 = new NguoiNhanThongBao();
                nguoiNhan1.NguoiNhanId = nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").NguoiGuiId;
                nhanThongBaos.Add(nguoiNhan1);
                // thêm vào thông báo
                Sys_QT_ThongBao obj1 = new Sys_QT_ThongBao();
                obj1.MaLenh        = luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.MaLenh;
                obj1.QuyTrinhId    = 1;
                obj1.TenNguoiGui   = user.FullName;
                obj1.NguoiNhanId   = nguoiNhans.FirstOrDefault(x => x.MaLenh == "VB_MOISOHOA").NguoiGuiId;
                obj1.NoiDung       = luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.NoiDung;
                obj1.NgayGui       = DateTime.Now;
                obj1.DaDoc         = false;
                obj1.NgayDoc       = null;
                obj1.TrangThaiXuLy = luanChuyenVbXNHT.VB_QT_LuanChuyenVanBan.TrangThaiXuLy;
                obj1.RouterLink    = "/vanban/quytrinhvanban/vanbandapheduyet";
                _context.Sys_QT_ThongBao.Add(obj1);
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0, nguoiNhanTbs = nhanThongBaos }));
            }
            catch (Exception)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }
        public async Task <IActionResult> r2addObjUnitCode()
        {
            try
            {
                var model = JsonConvert.DeserializeObject <VB_QT_VanBanMoiSoHoa>(Request.Form["model"]);
                VB_QT_VanBanMoiSoHoa objvb = new VB_QT_VanBanMoiSoHoa();
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                var userNguoiKy = await _context.Sys_Dm_User.FirstOrDefaultAsync(x => x.Id == model.NguoiKyId);

                if (model != null)
                {
                    objvb.Id           = Helper.GenKey();
                    objvb.CompanyId    = user.CompanyId ?? 0;
                    objvb.DepartmentId = user.DepartmentId ?? 0;
                    objvb.TenNguoiKy   = userNguoiKy.FullName;
                    objvb.LinhVucId    = model.LinhVucId;
                    objvb.LoaiVanBanId = model.LoaiVanBanId;
                    objvb.SoKyHieu     = model.SoKyHieu;
                    objvb.NoiBanHanh   = model.NoiBanHanh;
                    objvb.NgayBanHanh  = model.NgayBanHanh;
                    objvb.TuKhoa       = model.TuKhoa;
                    objvb.SoTrang      = model.SoTrang;
                    objvb.SoTrang      = model.SoTrang;
                    objvb.TenNguoiTao  = user.FullName;
                    objvb.CreateDate   = DateTime.Now;
                    objvb.UserCreateId = userId;
                    objvb.TrichYeu     = model.TrichYeu;
                    _context.VB_QT_VanBanMoiSoHoa.Add(objvb);
                }
                VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(objvb.Id, userId, user.FullName, userId, user.FullName, "", "", false, null, null, 1, "VB_MOISOHOA", DateTime.Now, false, null, "VB0101", "VB0101", user.PositionName, user.PositionName, user.DepartmentName, user.DepartmentName);
                _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                if (Request.Form.Files.Count != 0)
                {
                    foreach (var item in Request.Form.Files)
                    {
                        VB_QT_FileVBMoiSoHoa obj = new VB_QT_FileVBMoiSoHoa();
                        var file       = item;
                        var folderName = Path.Combine("Resources", "VanBan");
                        var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                        if (!Directory.Exists(pathToSave))
                        {
                            Directory.CreateDirectory(pathToSave);
                        }
                        if (model != null)
                        {
                            if (file.Length > 0)
                            {
                                var fileName = long.Parse(DateTime.Now.ToString("yyyyMMddHHmmss")).ToString() + ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                                var fullPath = Path.Combine(pathToSave, fileName);
                                var dbPath   = Path.Combine(folderName, fileName);
                                obj.Path = dbPath;
                                using (var stream = new FileStream(fullPath, FileMode.Create))
                                {
                                    file.CopyTo(stream);
                                }
                            }
                        }
                        obj.Name         = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                        obj.VbMoiSoHoaId = objvb.Id;
                        obj.Size         = file.Length;
                        obj.Type         = 1;
                        _context.VB_QT_FileVBMoiSoHoa.Add(obj);
                    }
                }
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0, ms = "" }));;
            }
            catch (Exception ex)
            {
                var result = new OkObjectResult(new { error = 1, ms = "Lỗi khi thêm mới UnitCode, vui lòng kiểm tra lại!" });
                return(result);
            }
        }
        public async Task <ActionResult <IEnumerable <VB_QT_VanBanMoiSoHoa> > > r2AddQTChuyenXuLy(LuanChuyenVbUser luanChuyenVbUser)
        {
            try
            {
                var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value);
                var user   = await _context.Sys_Dm_User.FindAsync(userId);

                var userNCD = await _context.Sys_Dm_User.FindAsync(luanChuyenVbUser.UserNhan.NguoiChiDaoId);

                var userNXL = await _context.Sys_Dm_User.FindAsync(luanChuyenVbUser.UserNhan.NguoiXuLyId);

                var userNDXL = await _context.Sys_Dm_User.FindAsync(luanChuyenVbUser.UserNhan.NguoiDXuLyId);

                var userNNDB = await _context.Sys_Dm_User.FindAsync(luanChuyenVbUser.UserNhan.NguoiNDBId);

                var qtLuanChuyenVb = _context.VB_QT_LuanChuyenVanBan.Where(x => x.VbMoiSoHoaId == luanChuyenVbUser.VB_QT_LuanChuyenVanBan.VbMoiSoHoaId &&
                                                                           x.NguoiNhanId == luanChuyenVbUser.VB_QT_LuanChuyenVanBan.NguoiGuiId &&
                                                                           x.MenuNhanId == luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuGuiId).OrderByDescending(x => x.ThoiGianGui).Take(1);
                if (luanChuyenVbUser.UserNhan.NguoiChiDaoId != null)
                {
                    VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.VbMoiSoHoaId, luanChuyenVbUser.UserNhan.NguoiChiDaoId, luanChuyenVbUser.UserNhan.TenNguoiChiDao, userId, user.FullName,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.TieuDe,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.NoiDung, false,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                        5,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MaLenh, null, false,
                        qtLuanChuyenVb.FirstOrDefault().Id,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuGuiId,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuNhanId,
                        userNCD.PositionName, user.PositionName, userNCD.DepartmentName, user.DepartmentName);
                    _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                }
                if (luanChuyenVbUser.UserNhan.NguoiXuLyId != null)
                {
                    VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.VbMoiSoHoaId, luanChuyenVbUser.UserNhan.NguoiXuLyId, luanChuyenVbUser.UserNhan.TenNguoiXuLy, userId, user.FullName,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.TieuDe,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.NoiDung, false,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                        6,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MaLenh, null, false,
                        qtLuanChuyenVb.FirstOrDefault().Id,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuGuiId,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuNhanId,
                        userNXL.PositionName, user.PositionName, userNXL.DepartmentName, user.DepartmentName);
                    _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                }
                if (luanChuyenVbUser.UserNhan.NguoiDXuLyId != null)
                {
                    VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.VbMoiSoHoaId, luanChuyenVbUser.UserNhan.NguoiDXuLyId, luanChuyenVbUser.UserNhan.TenNguoiDXuLy, userId, user.FullName,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.TieuDe,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.NoiDung, false,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                        7,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MaLenh, null, false,
                        qtLuanChuyenVb.FirstOrDefault().Id,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuGuiId,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuNhanId,
                        userNXL.PositionName, user.PositionName, userNXL.DepartmentName, user.DepartmentName);
                    _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                }
                if (luanChuyenVbUser.UserNhan.NguoiDXuLyId != null)
                {
                    VB_QT_LuanChuyenVanBan lcvb = LuanChuyenVanBan.r2AddLuanChuyenVanBan(
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.VbMoiSoHoaId, luanChuyenVbUser.UserNhan.NguoiNDBId, luanChuyenVbUser.UserNhan.TenNguoiNDB, userId, user.FullName,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.TieuDe,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.NoiDung, false,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.HanXuLy, null,
                        8,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MaLenh, null, false,
                        qtLuanChuyenVb.FirstOrDefault().Id,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuGuiId,
                        luanChuyenVbUser.VB_QT_LuanChuyenVanBan.MenuNhanId,
                        userNNDB.PositionName, user.PositionName, userNNDB.DepartmentName, user.DepartmentName);
                    _context.VB_QT_LuanChuyenVanBan.Add(lcvb);
                }
                await _context.SaveChangesAsync();

                return(new ObjectResult(new { error = 0 }));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new { error = 1 }));
            }
        }