public async Task <IHttpActionResult> Post(NhomQuyenViewModel.Dto instance) { var result = new TransferObj <NHOMQUYEN>(); var curentUnitCode = _service.GetCurrentUnitCode(); if (instance.MANHOMQUYEN == "") { result.Status = false; result.Message = "Mã không hợp lệ"; return(Ok(result)); } else { var exist = _service.Repository.DbSet.FirstOrDefault(x => x.MANHOMQUYEN == instance.MANHOMQUYEN && x.UNITCODE.Equals(curentUnitCode)); if (exist != null) { result.Status = false; result.Message = "Đã tồn tại mã khách hàng này"; return(Ok(result)); } } try { instance.MANHOMQUYEN = _service.SaveCode(); var data = Mapper.Map <NhomQuyenViewModel.Dto, NHOMQUYEN>(instance); var item = _service.Insert(data); int inst = await _service.UnitOfWork.SaveAsync(); if (inst > 0) { result.Status = true; result.Data = item; result.Message = "Thêm mới thành công"; } else { result.Status = false; result.Data = null; result.Message = "Thao tác không thành công"; } } catch (Exception e) { result.Status = false; result.Message = e.Message; } return(Ok(result)); }
public IHttpActionResult GetNhomQuyenChuaCauHinh(string userName) { var result = new TransferObj <List <NhomQuyenViewModel.Dto> >(); List <NhomQuyenViewModel.Dto> listNhomQuyen = new List <NhomQuyenViewModel.Dto>(); if (!string.IsNullOrEmpty(userName)) { try { string stringConnect = ConfigurationManager.ConnectionStrings["ERBusConnection"].ConnectionString; using (OracleConnection connection = new OracleConnection(stringConnect)) { try { connection.Open(); if (connection.State == ConnectionState.Open) { OracleCommand command = new OracleCommand(); command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = string.Format(@"SELECT a.ID, a.MANHOMQUYEN, a.TENNHOMQUYEN FROM NHOMQUYEN a WHERE a.MANHOMQUYEN NOT IN ( SELECT b.MANHOMQUYEN FROM NGUOIDUNG_NHOMQUYEN b WHERE b.USERNAME = :USERNAME) "); command.Parameters.Add(@"USERNAME", OracleDbType.NVarchar2, 50).Value = userName; OracleDataReader dataReader = command.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { NhomQuyenViewModel.Dto row = new NhomQuyenViewModel.Dto(); if (dataReader["ID"] != null) { row.ID = dataReader["ID"].ToString(); } if (dataReader["MANHOMQUYEN"] != null) { row.MANHOMQUYEN = dataReader["MANHOMQUYEN"].ToString(); } if (dataReader["TENNHOMQUYEN"] != null) { row.TENNHOMQUYEN = dataReader["TENNHOMQUYEN"].ToString(); } listNhomQuyen.Add(row); } } dataReader.Close(); } } catch (Exception ex) { } finally { connection.Close(); connection.Dispose(); } } if (listNhomQuyen.Count > 0) { result.Status = true; result.Data = listNhomQuyen; result.Message = "Thành công"; } else { result.Status = false; result.Data = null; result.Message = "Không có dữ liệu"; } } catch (Exception ex) { result.Status = false; result.Message = ex.Message; } } return(Ok(result)); }