예제 #1
0
        public async Task <int> CreateOrEdit(CreateOrEditHopDongInput hopDongInput)
        {
            var      input = hopDongInput.HopDong;
            DateTime Ngay_Sinh;

            if (input.Id == null)
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        await conn.OpenAsync();
                    }
                    var tableName = "HopDong";
                    var tenCTY    = input.TenCTY;
                    var result    = await conn.QueryAsync <string>(sql : "dbo.SYS_CodeMasters_Gen ", param : new { tableName, tenCTY }, commandType : CommandType.StoredProcedure);

                    var id = await Create(input);

                    var lichSu = hopDongInput.LichSuUpLoad;
                    if (lichSu.Count > 0)
                    {
                        for (int i = 0; i < lichSu.Count; i++)

                        {
                            var lichSuUpload = new LichSuUpload();

                            lichSuUpload.TenFile   = lichSu[i].TenFile;
                            lichSuUpload.TieuDe    = lichSu[i].TieuDe;
                            lichSuUpload.DungLuong = lichSu[i].DungLuong;
                            lichSuUpload.Type      = "HD";
                            lichSuUpload.TypeID    = id.ToString();
                            await _lichSuUploadRepository.InsertAsync(lichSuUpload);
                        }
                    }

                    return(id);
                }
            }
            else
            {
                await Update(input);
            }
            return(0);
        }
예제 #2
0
        public async Task <int> CreateOrEdit(CreateOrEditNghiPhepInput inputNghiPhep)
        {
            var      input = inputNghiPhep.NghiPhep;
            DateTime NgayBatDau, NgayKetThuc;

            NgayBatDau  = Convert.ToDateTime(input.NgayBatDau);
            NgayKetThuc = Convert.ToDateTime(input.NgayKetThuc);
            int now = int.Parse(NgayKetThuc.ToString("yyyyMMdd"));
            int dob = int.Parse(NgayBatDau.ToString("yyyyMMdd"));

            if (now >= dob)
            {
                if (input.Id == null)
                {
                    var id = await Create(input);

                    var lichSu = inputNghiPhep.LichSuUpLoad;

                    var quanLyTrucTiep = inputNghiPhep.QuanLyTrucTiepPNP;
                    if (lichSu.Count > 0)
                    {
                        for (int i = 0; i < lichSu.Count; i++)

                        {
                            var lichSuUpload = new LichSuUpload();

                            lichSuUpload.TenFile   = lichSu[i].TenFile;
                            lichSuUpload.TieuDe    = lichSu[i].TieuDe;
                            lichSuUpload.DungLuong = lichSu[i].DungLuong;
                            lichSuUpload.Type      = "NP";
                            lichSuUpload.TypeID    = id.ToString();
                            await _lichSuUploadRepository.InsertAsync(lichSuUpload);
                        }
                    }
                    if (quanLyTrucTiep.Count > 0)
                    {
                        for (int i = 0; i < quanLyTrucTiep.Count; i++)

                        {
                            var quanLyTrucTiepPNP = new QuanLyTrucTiepPNP();

                            quanLyTrucTiepPNP.QLTT            = quanLyTrucTiep[i].QLTT;
                            quanLyTrucTiepPNP.GhiChu          = quanLyTrucTiep[i].GhiChu;
                            quanLyTrucTiepPNP.MaHoSo          = quanLyTrucTiep[i].MaHoSo;
                            quanLyTrucTiepPNP.PhieuNghiPhepID = id;
                            await _quanLyTrucTiepPNPRepository.InsertAsync(quanLyTrucTiepPNP);
                        }
                    }
                    return(id);
                }
                else
                {
                    await Update(input);
                }
            }
            else
            {
                throw new UserFriendlyException(L(name: "Ngày kết thúc lớn hơn ngày bắt đầu"));
            }



            return(0);
        }