Ejemplo n.º 1
0
        public async void CreateCuTru()
        {
            var cuTru = new CuTruDTO
            {
                NgayDangKy  = dtpNgayDangKy.Value,
                NgayHetHan  = dtpNgayHetHan.Value,
                NgayTao     = dtpNgayTao.Value,
                Email       = txtEmail.Text,
                DienThoai   = txtDienThoai.Text,
                SoNha       = txtSoNha.Text,
                Duong       = txtDuong.Text,
                Phuong      = txtPhuong.Text,
                Quan        = txtQuan.Text,
                ThanhPho    = txtThanhPho.Text,
                LoaiCuTruId = cbLoaiCuTru.SelectedIndex + 1,
                CongDanIds  = danhSachCongDan
            };

            try
            {
                var url = await repo.CreateAsync(cuTru);

                MessageBox.Show("Đã tạo thành công cư trú mới", url.ToString());
            } catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task <Uri> CreateAsync(CuTruDTO cuTru)
        {
            HttpResponseMessage res = await client.PostAsJsonAsync(host, cuTru);

            res.EnsureSuccessStatusCode();

            return(res.Headers.Location);
        }
Ejemplo n.º 3
0
        public FormPrint(CuTruDTO CuTru)
        {
            _CuTru = CuTru;
            InitializeComponent();
            RptChiTietCuTru cr = new RptChiTietCuTru();

            crystalReportViewer.ReportSource = cr;
            rptChiTietCuTru.SetDataSource(_CuTru.CongDans);
        }
Ejemplo n.º 4
0
 private void dgvDanhSachChoDuyet_SelectionChanged(object sender, EventArgs e)
 {
     if (dgvDanhSachChoDuyet.SelectedRows.Count > 0)
     {
         var selectedRow = dgvDanhSachChoDuyet.SelectedRows[0];
         SelectedCuTru = (CuTruDTO)selectedRow.DataBoundItem;
         LoadDetailedData(SelectedCuTru);
     }
 }
Ejemplo n.º 5
0
 private void LoadDetailedData(CuTruDTO cuTru)
 {
     txtId.Text         = cuTru.Id.ToString();
     txtEmail.Text      = cuTru.Email;
     txtDienThoai.Text  = cuTru.DienThoai;
     txtNgayDangKy.Text = cuTru.NgayDangKy.ToShortDateString();
     txtLoaiCuTru.Text  = cuTru.LoaiCuTru;
     txtDiaChi.Text     = cuTru.DiaChi;
     lbSoNguoi.Text     = cuTru.CongDans.Count.ToString();
 }
Ejemplo n.º 6
0
        // PUT
        public async Task <bool> UpdateAsync(CuTruDTO cuTru)
        {
            HttpResponseMessage res = await client.PutAsJsonAsync(host + cuTru.Id, cuTru);

            if (res.StatusCode == HttpStatusCode.NoContent)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        public async Task <CuTruDTO> GetByIdAsync(int id)
        {
            CuTruDTO cuTru = null;

            // Request url template
            var url = $"{host}/{id}";

            HttpResponseMessage res = await client.GetAsync(url);

            if (res.IsSuccessStatusCode)
            {
                cuTru = await res.Content.ReadAsAsync <CuTruDTO>();
            }

            return(cuTru);
        }
        public IHttpActionResult CreateCuTru(CuTruDTO dto)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest());
            }

            var cuTru = Mapper.Map <CuTruDTO, CuTru>(dto);

            // Create an empty CongDans instance
            cuTru.CongDans = new Collection <NguoiDung>();

            // Add CongDan entities into posted CuTru
            foreach (var id in dto.CongDanIds)
            {
                // Query each congdan
                var congDan = db.NguoiDungs.SingleOrDefault(c => c.Id == id);

                if (congDan == null)
                {
                    return(BadRequest());
                }

                cuTru.CongDans.Add(congDan);
            }

            // If CanhSatKhuVuc
            if (User.IsInRole("CanhSatKhuVuc"))
            {
                // Get the logged in CanBo's id
                var currentId = User.Identity.GetUserId();

                // Get CanBo entity in db
                var canBo = db.NguoiDungs.SingleOrDefault(c => c.IdentityId.Equals(currentId));

                cuTru.DaDuyet = true;     // Set DaDuyet state to true
                cuTru.CanBoId = canBo.Id; // Set CanBo Duyet id
            }

            db.CuTrus.Add(cuTru);
            db.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "" + cuTru.Id), cuTru));
        }
        public IHttpActionResult UpdateCuTru(int id, CuTruDTO dto)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest());
            }

            var cuTru = db.CuTrus.SingleOrDefault(c => c.Id == id);

            if (cuTru == null)
            {
                return(NotFound());
            }

            Mapper.Map(dto, cuTru);

            db.SaveChanges();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 10
0
 public FormChiTietCuTru(CuTruDTO cuTru)
 {
     CuTru = cuTru;
     InitializeComponent();
     LoadCuTruData();
 }