Пример #1
0
        /*public string MaPhongBan { get; set; }
         * public string TenPhongBan { get; set; }
         * public string GhiChu { get; set; } */
        #endregion

        public async Task <ActionResultDto> Execute(ContextDto context)
        {
            try
            {
                validate();

                var phongban = new Entity.MSSQL_QLDN_QLNS.Entity.PhongBan();
                phongban.MaPhongBan  = MaPhongBan;
                phongban.TenPhongBan = TenPhongBan;
                phongban.GhiChu      = GhiChu;


                PhongBanRepository repo = new PhongBanRepository(context);
                await repo.Insert(phongban);

                return(returnActionResult(HttpStatusCode.OK, phongban, 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));
            }
        }
Пример #2
0
        public async Task <ActionResultDto> Execute(ContextDto context)
        {
            try
            {
                init();
                validate();

                var count = 0;

                var repo = new PhongBanRepository(context);

                for (int i = 0; i < _listId.Count; i++)
                {
                    if (_listId[i] > 0 && await repo.Delete(_listId[i]))
                    {
                        count++;
                    }
                }

                return(returnActionResult(HttpStatusCode.OK, count, 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));
            }
        }
Пример #3
0
        public async Task <dynamic> Execute(ContextDto context)
        {
            try
            {
                dynamic result = new System.Dynamic.ExpandoObject();

                var repo = new PhongBanRepository(context);
                await repo.UpdatePartial(this,
                                         nameof(PhongBan.MaPhongBan),
                                         nameof(PhongBan.TenPhongBan),
                                         nameof(PhongBan.GhiChu),
                                         nameof(PhongBan.XoaYN)
                                         );

                result.data = this;
                return(result);
            }
            catch (FormatException ex)
            {
                return(returnActionError(HttpStatusCode.BadRequest, ex.Message));
            }
            catch (Exception ex)
            {
                return(returnActionError(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #4
0
        public async Task <ActionResultDto> Execute(ContextDto context)
        {
            GetListPhongBanByCriteriaBiz biz = new GetListPhongBanByCriteriaBiz(context);
            var result = new ActionResultDto();

            try
            {
                var _draw   = Protector.Int(draw);
                var _start  = Protector.Int(start);
                var _length = Protector.Int(length);

                /* =========================
                 * fixed input
                 * ========================= */
                sortName = string.IsNullOrEmpty(sortName) ? "PhongBanId" : sortName;
                sortDir  = string.IsNullOrEmpty(sortDir) ? "asc" : sortDir;
                _length  = _length < 1 ? 10 : _length;
                fields   = string.IsNullOrEmpty(fields) ? "PhongBanId,TenPhongBan,MaPhongBan,GhiChu,NgayTao,NguoiTao,CtrVersion" : fields;

                var whereClause = string.Format("MaPhongBan LIKE N'%{0}%' OR TenPhongBan LIKE N'%{0}%'", search);
                var orderClause = sortName + " " + sortDir;
                var total       = 0;

                biz.FieldsField = fields;
                biz.WhereClause = whereClause;
                biz.OrderClause = orderClause;
                biz.Skip        = _start;
                biz.Take        = _length;

                PhongBanRepository    repo         = new PhongBanRepository(context);
                IEnumerable <dynamic> listPhongBan = await biz.Execute();

                if (listPhongBan.Count() > 0)
                {
                    var obj = listPhongBan.FirstOrDefault();

                    total = Protector.Int(obj.MAXCNT);
                }

                dynamic _metaData = new System.Dynamic.ExpandoObject();
                _metaData.draw  = _draw;
                _metaData.total = total;

                return(ActionHelper.returnActionResult(HttpStatusCode.OK, listPhongBan, _metaData));
            }
            catch (Exception ex)
            {
                result.ReturnCode = HttpStatusCode.InternalServerError;
                result.ReturnData = new
                {
                    error = new
                    {
                        code    = HttpStatusCode.InternalServerError,
                        type    = HttpStatusCode.InternalServerError.ToString(),
                        message = ex.InnerException != null ? ex.InnerException.Message : ex.Message
                    }
                };
                return(result);
            }
        }
Пример #5
0
        public async Task <dynamic> Execute(ContextDto context)
        {
            dynamic result = new System.Dynamic.ExpandoObject();

            var repo = new PhongBanRepository(context);
            await repo.Delete(Id);

            result.data = await repo.Delete(Id);

            return(result);
        }
        public ActionResult ExportExcel()
        {
            try
            {
                var                  webRoot = _env.WebRootPath;
                DataTable            dt      = new DataTable();
                QuanLyCongVanContext db      = new QuanLyCongVanContext();
                var                  paht    = System.IO.Path.Combine(webRoot, "Content/TempExcel/PhongBan.xlsx");
                Workbook             wb      = new Workbook();

                //Cell Cells = char.Parse(new Cell["A3"].ToString());
                Worksheet ws = wb.Worksheets[0];
                dt.Columns.Add("Mã phòng");
                dt.Columns.Add("Tên");;
                dt.Columns.Add("Điện  thoại");
                dt.Columns.Add("Fax");
                dt.Columns.Add("Mã nhân sự");
                List <PhongBan> listpb = new List <PhongBan>();
                listpb = db.PhongBan.ToList();
                string listpbs = "";
                if (listpb.Count > 0)
                {
                    listpbs = String.Join(",", listpb.Select(x => x.ToString()).ToArray());
                }
                var ob   = new PhongBanRepository();
                var data = ob.GetAll();
                foreach (PhongBan item in data)
                {
                    dt.Rows.Add(item.MaPhong, item.TenPhong, item.DienThoai, item.Fax, item.MaNhanSu);
                }
                string filename   = "DanhSachPhongBan" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".xlsx";
                string folderName = "/assets/Excel/";

                var file = System.IO.Path.Combine(webRoot + folderName + filename);
                if (!System.IO.Directory.Exists(folderName))
                {
                    System.IO.Directory.CreateDirectory(folderName);
                }
                ws.Cells.ImportDataTable(dt, false, 2, 0);
                wb.Save(file);
                return(Json(folderName + filename));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        public async Task<ActionResultDto> Execute(ContextDto context)
        {
            var _result = new ActionResultDto();
            try
            {
                /* kiểm tra input */
                var _error = validate();

                if (_error.code > 0)
                {
                    return returnActionError(HttpStatusCode.BadRequest, _error.message);
                }

                /* convert input */
                var _PhongBanId = Protector.Int(PhongBanId);

                var repo = new PhongBanRepository(context);
                var PhongBan = await repo.GetById(_PhongBanId);

                if (PhongBan == null)
                {
                    return returnActionError(HttpStatusCode.BadRequest, string.Format("Không tìm thấy PhongBanId '{0}'", _PhongBanId));
                }

                _result.ReturnCode = HttpStatusCode.OK;
                _result.ReturnData = new
                {
                    data = PhongBan
                };

                return _result;
            }
            catch (Exception ex)
            {
                return returnActionError(HttpStatusCode.InternalServerError, ex.InnerException != null ? ex.InnerException.Message : ex.Message);
            }
        }
Пример #8
0
 public PhongBanController(PhongBanRepository repository)
 {
     _repository = repository ?? throw new ArgumentNullException(nameof(repository));
 }
Пример #9
0
 public PhongBanService(PhongBanRepository phongBanRepository)
 {
     _phongBanRepository = phongBanRepository;
 }