Exemplo n.º 1
0
        public async Task <ActionResultDto> Execute(ContextDto context)
        {
            try
            {
                var duan = new Entity.MSSQL_QLDN_QLNS.Entity.DuAn();
                duan.TenDuAn     = TenDuAn;
                duan.MoTa        = MoTa;
                duan.MaTrangThai = MaTrangThai;
                duan.PhongBan    = Protector.Int(PhongBan);
                duan.QuanLy      = Protector.Int(QuanLy);
                if (NgayBatDau != "" && NgayBatDau != null)
                {
                    duan.NgayBatDau = DateTime.ParseExact(NgayBatDau, "dd/MM/yyyy", CultureInfo.GetCultureInfo("fr-FR"));
                }
                if (NgayThatSuBatDau != null && NgayThatSuBatDau != "")
                {
                    duan.NgayThatSuBatDau = DateTime.ParseExact(NgayThatSuBatDau, "dd/MM/yyyy", CultureInfo.GetCultureInfo("fr-FR"));
                }
                if (NgayKetThuc != null && NgayKetThuc != "")
                {
                    duan.NgayKetThuc = DateTime.ParseExact(NgayKetThuc, "dd/MM/yyyy", CultureInfo.GetCultureInfo("fr-FR"));
                }
                if (NgayThatSuKetThuc != null && NgayThatSuKetThuc != "")
                {
                    duan.NgayThatSuKetThuc = DateTime.ParseExact(NgayThatSuKetThuc, "dd/MM/yyyy", CultureInfo.GetCultureInfo("fr-FR"));
                }
                duan.NguoiTao   = Protector.Int(NguoiTao);
                duan.NgayTao    = DateTime.Now;
                duan.XoaYN      = "N";
                duan.CtrVersion = 1;
                DuAnRepository repo = new DuAnRepository(context);
                await repo.Insert(duan);

                InsertLuocSuAction ls = new InsertLuocSuAction();
                ls.InsertLuocSu(context, "DuAn", duan.DuAnId, "Insert", duan.NguoiTao);
                if (NhanVien != "" && NhanVien != null)
                {
                    var nvda  = new Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn();
                    var nvids = NhanVien.Split('|');
                    foreach (var nv in nvids)
                    {
                        nvda.DuAnId     = duan.DuAnId;
                        nvda.XoaYN      = "N";
                        nvda.NhanVienId = Protector.Int(nv);
                        await repo.InsertNV(nvda);
                    }
                }
                return(returnActionResult(HttpStatusCode.OK, duan, null));
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.InnerException != null ? ex.InnerException.Message : ex.Message));
            }
        }
Exemplo n.º 2
0
        public async Task <dynamic> Execute(ContextDto context)
        {
            try
            {
                dynamic result = new System.Dynamic.ExpandoObject();
                var     repo   = new DuAnRepository(context);
                await repo.UpdatePartial(this,
                                         nameof(TenDuAn),
                                         nameof(MoTa),
                                         nameof(MaTrangThai),
                                         nameof(PhongBan),
                                         nameof(QuanLy),
                                         nameof(NgayBatDau),
                                         nameof(NgayThatSuBatDau),
                                         nameof(NgayKetThuc),
                                         nameof(CtrVersion),
                                         nameof(NgayThatSuKetThuc)
                                         );

                result.data = this;
                InsertLuocSuAction ls = new InsertLuocSuAction();
                ls.InsertLuocSu(context, "DuAn", DuAnId, "Update", NguoiTao);
                Data.QLNS.DuAn.DeleteOneNhanVienDuAnDac dac = new Data.QLNS.DuAn.DeleteOneNhanVienDuAnDac(context);
                dac.DuAnId = DuAnId.ToString();
                await dac.Execute();

                if (NhanVien != null && NhanVien != "")
                {
                    var nvda  = new Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn();
                    var nvids = NhanVien.Split('|');
                    foreach (var nv in nvids)
                    {
                        nvda.DuAnId     = DuAnId;
                        nvda.XoaYN      = "N";
                        nvda.NhanVienId = Protector.Int(nv);
                        await repo.InsertNV(nvda);
                    }
                }
                return(returnActionResult(this, null));
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <dynamic> Execute(ContextDto context)
        {
            try
            {
                init();
                validate();
                var repo = new DuAnRepository(context);
                if (_DuAn != null)
                {
                    var duanEntity = new Entity.MSSQL_QLDN_QLNS.Entity.DuAn();
                    duanEntity.DuAnId     = _DuAn.DuAnId;
                    duanEntity.CtrVersion = _DuAn.CtrVersion;

                    duanEntity.XoaYN = "Y";

                    duanEntity = await repo.UpdatePartial(duanEntity,
                                                          nameof(Entity.MSSQL_QLDN_QLNS.Entity.DuAn.XoaYN)
                                                          );

                    _DuAn.XoaYN = duanEntity.XoaYN;
                    if (_DuAn.NhanVienDa.Length > 0)
                    {
                        var nvda  = new Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn();
                        var nvids = _DuAn.NhanVienDa.Split('|');
                        foreach (var nv in nvids)
                        {
                            nvda.DuAnId     = _DuAn.DuAnId;
                            nvda.NhanVienId = Protector.Int(nv);
                            nvda.XoaYN      = "Y";
                            nvda            = await repo.UpdatePartialNV(nvda,
                                                                         nameof(Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn.XoaYN)
                                                                         );
                        }
                    }
                }
                else
                {
                    if (_listDuAn != null && _listDuAn.Count > 0)
                    {
                        foreach (var duanModel in _listDuAn)
                        {
                            if (duanModel.DuAnId > 0)
                            {
                                var duanEntity = new Entity.MSSQL_QLDN_QLNS.Entity.DuAn();
                                duanEntity.DuAnId     = duanModel.DuAnId;
                                duanEntity.CtrVersion = duanModel.CtrVersion;

                                duanEntity.XoaYN = "Y";

                                duanEntity = await repo.UpdatePartial(duanEntity,
                                                                      nameof(Entity.MSSQL_QLDN_QLNS.Entity.DuAn.XoaYN)
                                                                      );

                                duanModel.XoaYN = duanEntity.XoaYN;
                                if (duanModel.NhanVienDa != null)
                                {
                                    var nvda  = new Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn();
                                    var nvids = duanModel.NhanVienDa.Split('|');
                                    foreach (var nv in nvids)
                                    {
                                        nvda.DuAnId     = duanModel.DuAnId;
                                        nvda.NhanVienId = Protector.Int(nv);
                                        nvda.XoaYN      = "Y";
                                        nvda            = await repo.UpdatePartialNV(nvda,
                                                                                     nameof(Entity.MSSQL_QLDN_QLNS.Entity.NhanVienDuAn.XoaYN)
                                                                                     );
                                    }
                                }
                            }
                        }
                    }
                }

                return(ActionHelper.returnActionResult(HttpStatusCode.OK, _listDuAn, null));
            }
            catch (FormatException ex)
            {
                return(ActionHelper.returnActionError(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(ActionHelper.returnActionError(HttpStatusCode.InternalServerError, ex.Message));
            }
        }