public async Task <IHttpActionResult> GetAllDataTrade(string codeTrade) { TransferObj <NvGiaoDichQuayVm.DataDto> result = new TransferObj <NvGiaoDichQuayVm.DataDto>(); NvGiaoDichQuayVm.DataDto instance = new NvGiaoDichQuayVm.DataDto(); try { NvGiaoDichQuay data = _service.Repository.DbSet.FirstOrDefault(x => x.MaGiaoDich == codeTrade); if (data != null) { instance = Mapper.Map <NvGiaoDichQuay, NvGiaoDichQuayVm.DataDto>(data); instance = _serviceRetails.SetCustomer(instance); instance.DataDetails = _serviceRetails.DataDetails(instance); result.Data = instance; result.Status = true; return(Ok(result)); } else { result.Data = new NvGiaoDichQuayVm.DataDto(); result.Status = false; return(Ok(result)); } } catch (Exception) { result.Data = new NvGiaoDichQuayVm.DataDto(); result.Status = false; return(Ok(result)); } }
public void LoadDataSource() { this.DataSource = null; NvGiaoDichQuayVm.DataDto obj = new NvGiaoDichQuayVm.DataDto(); string a = this.ReportParameters[0].Text.ToString(); var jsonObj = JObject.Parse(a); var filtered = ((JObject)jsonObj).ToObject <NvGiaoDichQuayVm.DataDto>(); }
public async Task <IHttpActionResult> GetGiaoDichByVoucher(string maGiamGia) { var temp = new NvGiaoDichQuayVm.Dto(); var _parentUnitCode = _service.GetParentUnitCode(); var result = new TransferObj <NvGiaoDichQuayVm.Dto>(); NvGiaoDichQuayVm.DataDto instance = new NvGiaoDichQuayVm.DataDto(); var phieu = _serviceGdq.Repository.DbSet.FirstOrDefault(x => x.MaVoucher == maGiamGia && x.UnitCode.StartsWith(_parentUnitCode)); if (phieu != null) { instance = Mapper.Map <NvGiaoDichQuay, NvGiaoDichQuayVm.DataDto>(phieu); temp = Mapper.Map <NvGiaoDichQuay, NvGiaoDichQuayVm.Dto>(phieu); var chiTietPhieu = _service.UnitOfWork.Repository <NvGiaoDichQuayChiTiet>() .DbSet.Where(x => x.MaGDQuayPK == phieu.MaGiaoDichQuayPK) .ToList(); temp.DataDetails = Mapper.Map <List <NvGiaoDichQuayChiTiet>, List <NvGiaoDichQuayVm.DtoDetail> >(chiTietPhieu).ToList(); if (!string.IsNullOrEmpty(instance.MaKhachHang)) { var customer = _service.UnitOfWork.Repository <MdCustomer>().DbSet.FirstOrDefault(x => x.MaKH == instance.MaKhachHang && x.UnitCode.StartsWith(_parentUnitCode)); if (customer != null) { temp.DiaChi = customer.DiaChi; temp.DienThoai = customer.DienThoai; temp.NgaySinh = customer.NgaySinh; temp.NgayDacBiet = customer.NgayDacBiet; temp.Email = customer.Email; temp.TenKhachHang = customer.TenKH; temp.MaThe = customer.MaThe; temp.QuenThe = customer.QuenThe; temp.TongTien = customer.TongTien; temp.TienNguyenGia = customer.TienNguyenGia; temp.TienSale = customer.TienSale; temp.HangKhachHang = customer.HangKhachHang; } } result.Data = temp; result.Status = true; return(Ok(result)); } else { result.Data = null; result.Message = "Không tìm thấy bản ghi"; result.Status = false; } return(Ok(result)); }
public async Task <IHttpActionResult> Post(NvGiaoDichQuayVm.DataDto instance) { var result = new TransferObj <NvGiaoDichQuay>(); var _parentUnitCode = _serviceGdQuay.GetParentUnitCode(); try { //lưu giao dịch var item = _serviceRetails.InsertPhieu(instance); //run XNT tăng giảm phiếu //update thông tin khách hàng await _serviceRetails.UnitOfWork.SaveAsync(); if (item.MaGiaoDichQuayPK != "" && item.LoaiGiaoDich > 0) { int loaiGiaoDich = 0; Int32.TryParse(item.LoaiGiaoDich.ToString(), out loaiGiaoDich); _serviceRetails.RUNSTORE_TANGGIAM_TON(item.MaGiaoDichQuayPK, loaiGiaoDich); } //update customer if (instance.Makh != "KHACHLE") { SaveCustomer(instance.Makh, instance); } await _serviceCustomer.UnitOfWork.SaveAsync(); //update only one use voucher code if (item.MaVoucher != null) { //check code voucher in NVKhuyenMai var itemVoucher = _serviceGdQuay.UnitOfWork.Repository <NvChuongTrinhKhuyenMai>() .DbSet.FirstOrDefault(x => x.LoaiKhuyenMai == 7 && x.MaGiamGia == item.MaVoucher && x.UnitCode.StartsWith(_parentUnitCode)); if (itemVoucher != null) { itemVoucher.TrangThaiSuDung = (int)ApprovalState.IsExpired; _serviceKhuyenMaiVoucher.Update(itemVoucher); await _serviceKhuyenMaiVoucher.UnitOfWork.SaveAsync(); } } result.Data = item; result.Status = true; return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.MaGiaoDichQuayPk }, result)); } catch (Exception exception) { return(InternalServerError()); } }
public void SaveCustomer(string maKhachHang, NvGiaoDichQuayVm.DataDto instance) { bool flag = false; decimal tienNguyenGia = 0, sumTienNguyenGia = 0, tienSale = 0, sumTienSale = 0, tongTien = 0, soDiem = 0; int quenThe = 0; var _parentUnitCode = _serviceCustomer.GetParentUnitCode(); var khachHang = _serviceCustomer.Repository.DbSet.FirstOrDefault(x => x.MaKH == maKhachHang && x.UnitCode.StartsWith(_parentUnitCode)); if (khachHang != null) { foreach (var record in instance.DataDetails) { if (instance.IsTichDiem) { flag = true; } if (record != null && record.TienKhuyenMai > 0) { decimal.TryParse(record.ThanhTien.ToString(), out tienSale); sumTienSale = sumTienSale + tienSale; } else { decimal.TryParse(record.ThanhTien.ToString(), out tienNguyenGia); sumTienNguyenGia = sumTienNguyenGia + tienNguyenGia; } } decimal.TryParse(instance.SumTienHang.ToString(), out soDiem); if (flag) { soDiem = soDiem * 2; } tongTien = sumTienNguyenGia + sumTienSale; //có rồi -- update int.TryParse(instance.QuenThe.ToString(), out quenThe); _serviceCustomer.UpdateCustomerAfterPurchase(sumTienNguyenGia, sumTienSale, tongTien, soDiem, quenThe, khachHang.Id); } else //chưa có khách hàng này { var kh = new MdCustomer(); kh.MaKH = instance.Makh; kh.TenKH = instance.TenKH; kh.TenKhac = instance.TenKH; kh.DiaChi = instance.DiaChi; kh.DienThoai = instance.DienThoai; kh.NgaySinh = instance.NgaySinh; kh.NgayDacBiet = instance.NgayDacBiet; kh.Email = instance.Email; kh.MaThe = instance.MaThe; kh.SoDiem = instance.TTienCoVat; kh.QuenThe = 0; foreach (var record in instance.DataDetails) { if (record != null && record.TienKhuyenMai > 0) { decimal.TryParse(record.ThanhTien.ToString(), out tienSale); sumTienSale = sumTienSale + tienSale; } else { decimal.TryParse(record.ThanhTien.ToString(), out tienNguyenGia); sumTienNguyenGia = sumTienNguyenGia + tienNguyenGia; } } decimal.TryParse(instance.TTienCoVat.ToString(), out soDiem); tongTien = sumTienNguyenGia + sumTienSale; int quenTheNew = 0; _serviceCustomer.Insert(kh); _serviceCustomer.UpdateCustomerAfterPurchase(sumTienNguyenGia, sumTienSale, tongTien, soDiem, quenTheNew, kh.Id); } }