public IEnumerable <CustomerBookedEventModel> AllBookedEventsOnADate(DateTime df) { using (nathusfeedback_androidEntities context = new nathusfeedback_androidEntities()) { int year = df.Year; int month = df.Month; int day = df.Day; //DateTime startDate = new DateTime(df.Year, df.Month, df.Day); //DateTime endDate = new DateTime(df.Year, df.Month, df.Day); var data = (from o in context.customerordermasters join e in context.customereventmasters on o.CustomerId equals e.CustomerId into J1 from j2 in J1.DefaultIfEmpty() join c in context.customermasters on o.CustomerId equals c.CustomerId into j3 from j4 in j3.DefaultIfEmpty() where j2.EventDate.Value.Year == df.Year && j2.EventDate.Value.Month == df.Month && j2.EventDate.Value.Day == df.Day select new CustomerBookedEventModel() { EventDate = (DateTime)j2.EventDate, Time = j2.Time, OrderId = o.OrderId, OrderNumber = o.OrderNumber, CustomerName = j4.CustomerName, PhoneNumber = j4.PhoneNumber, StoreId = (int)j2.StoreId, }).ToList(); return(data); } }
private async Task <UserCacheDto> GetUserCacheFromDB(long Id) { var query = await(from User in _userRepository.GetAll().Where(w => w.Id == Id) join KhachHang in _khachHangRepository.GetAll() on User.Id equals KhachHang.UserId into J1 from KhachHang in J1.DefaultIfEmpty() select new { User.Id, User.UserName, User.Name, User.IsCustomer, CustomerId = KhachHang != null ? KhachHang.Id : 0 }).FirstOrDefaultAsync(); var result = new UserCacheDto(); if (query != null) { result.Id = query.Id; result.UserName = query.UserName; result.Name = query.Name; result.IsCustomer = query.IsCustomer; if (query.CustomerId > 0) { result.CustomerId = query.CustomerId; } } return(result); }
public async Task <PagedResultDto <GetUserForView> > GetAllNew(PagedUserResultRequestDto input) { var query = from User in _userRepository.GetAllIncluding(x => x.Roles) .Where(w => w.IsCustomer == false) .WhereIf(!input.Keyword.IsNullOrWhiteSpace(), x => x.UserName.Contains(input.Keyword) || x.Name.Contains(input.Keyword) || x.PhoneNumber.Contains(input.Keyword) || x.EmailAddress.Contains(input.Keyword)) .WhereIf(input.IsActive.HasValue, x => x.IsActive == input.IsActive) join TramDichVu in _tramDichVuRepository.GetAll() on User.TramDichVuId equals TramDichVu.Id into J1 from TramDichVu in J1.DefaultIfEmpty() where input.TramDichVuId == null || TramDichVu.Id == input.TramDichVuId select new { User, TramDichVuName = TramDichVu != null ? TramDichVu.Name : "", TramTruongId = TramDichVu != null ? TramDichVu.TramTruongId : 0 }; var TotalCount = await query.CountAsync(); var PagedUser = await query.OrderBy(o => o.User.UserName).PageBy(input).ToListAsync(); var PagedUserForView = PagedUser.Select(s => new GetUserForView { User = ObjectMapper.Map <UserDto>(s.User), TramDichVuName = s.TramDichVuName, VaiTroName = s.User.Id == s.TramTruongId ? "Trạm trưởng" : s.TramTruongId > 0 ? "Nhân viên" : "" }).ToList(); return(new PagedResultDto <GetUserForView>( TotalCount, PagedUserForView )); }
public override async Task <DanhMucHangMucDto> Get(EntityDto <int> input) { var query = await(from HangMuc in _danhMucHangMucRepository.GetAll().Where(w => w.Id == input.Id) join DichVu in _danhMucDichVuRepository.GetAll() on HangMuc.DichVuId equals DichVu.Id into J1 from DichVu in J1.DefaultIfEmpty() join NhomDichVu in _danhMucNhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J2 from NhomDichVu in J2.DefaultIfEmpty() select new { HangMuc, NhomDichVuId = NhomDichVu != null ? NhomDichVu.Id : 0 }).FirstOrDefaultAsync(); if (query == null) { throw new UserFriendlyException("Không tìm thấy Hạng Mục!"); } var GetHangMuc = ObjectMapper.Map <DanhMucHangMucDto>(query.HangMuc); if (query.NhomDichVuId > 0) { GetHangMuc.NhomDichVuId = query.NhomDichVuId; } return(GetHangMuc); }
public override async Task <PagedResultDto <CongViecDto> > GetAll(GetAllCongViecInput input) { input.Keyword = GlobalFunction.RegexFormat(input.Keyword); var query = from CongViec in _congViecRepository.GetAll() .WhereIf(!string.IsNullOrEmpty(input.Keyword), w => w.KhachHangName.Contains(input.Keyword) || w.SoDienThoai.Contains(input.Keyword)) .WhereIf(input.TramDichVuId.HasValue, w => w.TramDichVuId == input.TramDichVuId || (input.TramDichVuId == 0 && w.TramDichVuId == null)) .WhereIf(input.TrangThaiId.HasValue, w => w.TrangThaiId == input.TrangThaiId) join DichVu in _dichVuRepository.GetAll() on CongViec.DichVuId equals DichVu.Id into J1 from DichVu in J1.DefaultIfEmpty() join TramDichVu in _tramDichVuRepository.GetAll() on CongViec.TramDichVuId equals TramDichVu.Id into J5 from TramDichVu in J5.DefaultIfEmpty() join NhanVien in _nhanVienRepository.GetAll() on CongViec.NhanVienId equals NhanVien.Id into J2 from NhanVien in J2.DefaultIfEmpty() join TinhThanh in _tinhThanhRepository.GetAll() on CongViec.DiaChiTinhThanhId equals TinhThanh.Id into J3 from TinhThanh in J3.DefaultIfEmpty() join QuanHuyen in _quanHuyenRepository.GetAll() on CongViec.DiaChiQuanHuyenId equals QuanHuyen.Id into J4 from QuanHuyen in J4.DefaultIfEmpty() select new { CongViec, DichVuName = DichVu.Name, TramDichVuName = TramDichVu.Name, NhanVienName = NhanVien.Name, TinhThanhName = TinhThanh.Name, QuanHuyenName = QuanHuyen.Name }; var TotalCount = await query.CountAsync(); var PagedCongViec = await query.OrderBy(o => o.CongViec.NgayGioHen).PageBy(input).ToListAsync(); var CongViecs = new List <CongViecDto>(); foreach (var item in PagedCongViec) { var CongViec = ObjectMapper.Map <CongViecDto>(item.CongViec); CongViec.DichVuName = item.DichVuName; CongViec.TramDichVuName = item.TramDichVuName; CongViec.NhanVienName = item.NhanVienName; CongViec.DiaChi += string.IsNullOrWhiteSpace(item.QuanHuyenName) ? "" : ", " + item.QuanHuyenName; CongViec.DiaChi += string.IsNullOrWhiteSpace(item.TinhThanhName) ? "" : ", " + item.TinhThanhName; CongViec.TrangThaiName = item.CongViec.TrangThaiId >= 0 && GlobalModel.TrangThaiCongViec.ContainsKey((int)item.CongViec.TrangThaiId) ? GlobalModel.TrangThaiCongViec[(int)item.CongViec.TrangThaiId] : ""; CongViecs.Add(CongViec); } return(new PagedResultDto <CongViecDto> { TotalCount = TotalCount, Items = CongViecs }); }
public override async Task <PagedResultDto <DanhMucHangMucDto> > GetAll(GetAllDanhMucHangMucInput input) { string Keyword = GlobalFunction.RegexFormat(input.Keyword); var query = from HangMuc in _danhMucHangMucRepository.GetAll() .WhereIf(!string.IsNullOrWhiteSpace(Keyword), w => w.Name.Contains(Keyword)) .WhereIf(input.DichVuId.HasValue, w => w.DichVuId == input.DichVuId) .WhereIf(input.IsActive.HasValue, w => w.IsActive == input.IsActive) join DichVu in _danhMucDichVuRepository.GetAll() on HangMuc.DichVuId equals DichVu.Id into J1 from DichVu in J1.DefaultIfEmpty() join NhomDichVu in _danhMucNhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J2 from NhomDichVu in J2.DefaultIfEmpty() where !input.NhomDichVuId.HasValue || NhomDichVu.Id == input.NhomDichVuId select new { HangMuc, DichVuName = DichVu != null ? DichVu.Name : "", NhomDichVuName = NhomDichVu != null ? NhomDichVu.Name : "" }; var TotalCount = await query.CountAsync(); var PagedHangMuc = await query.OrderBy(o => o.HangMuc.Name).PageBy(input).ToListAsync(); List <DanhMucHangMucDto> HangMucs = new List <DanhMucHangMucDto>(); foreach (var item in PagedHangMuc) { var HangMuc = ObjectMapper.Map <DanhMucHangMucDto>(item.HangMuc); HangMuc.DichVuName = item.DichVuName; HangMuc.NhomDichVuName = item.NhomDichVuName; HangMucs.Add(HangMuc); } return(new PagedResultDto <DanhMucHangMucDto> { TotalCount = TotalCount, Items = HangMucs }); }
public async Task <PagedResultDto <GetTramDichVuForView> > GetAllNew(GetAllTramDichVuInput input) { input.Keyword = GlobalFunction.RegexFormat(input.Keyword); var query = from TramDV in _tramDichVuRepository.GetAll() .WhereIf(!input.Keyword.IsNullOrWhiteSpace(), w => w.Name.Contains(input.Keyword)) join TramTruong in _userRepository.GetAll() on TramDV.TramTruongId equals TramTruong.Id into J1 from TramTruong in J1.DefaultIfEmpty() join DmQuanHuyen in _danhMucQuanHuyenRepository.GetAll() on TramDV.DiaChiQuanHuyenId equals DmQuanHuyen.Id into J2 from DmQuanHuyen in J2.DefaultIfEmpty() join DmTinhThanh in _danhMucTinhThanhRepository.GetAll() on TramDV.DiaChiTinhThanhId equals DmTinhThanh.Id into J3 from DmTinhThanh in J3.DefaultIfEmpty() select new { TramDV, TramTruongName = TramTruong != null ? TramTruong.UserName : "", QuanHuyenName = DmQuanHuyen != null ? ", " + DmQuanHuyen.Name : "", TinhThanhName = DmTinhThanh != null ? ", " + DmTinhThanh.Name : "", }; var TotalCount = await query.CountAsync(); var PagedDanhMucTram = await query.OrderBy(o => o.TramDV.Name).PageBy(input).ToListAsync(); var PagedDanhMucTramForView = PagedDanhMucTram.Select(s => new GetTramDichVuForView { TramDichVu = ObjectMapper.Map <TramDichVuDto>(s.TramDV), TramTruongName = s.TramTruongName, DiaChi = s.TramDV.DiaChi + s.QuanHuyenName + s.TinhThanhName, }).ToList(); return(new PagedResultDto <GetTramDichVuForView> ( TotalCount, PagedDanhMucTramForView )); }
public override async Task <PagedResultDto <DanhMucDichVuDto> > GetAll(GetAllDanhMucDichVuInput input) { string Keyword = GlobalFunction.RegexFormat(input.Keyword); var query = from DichVu in _danhMucDichVuRepository.GetAll() .WhereIf(!string.IsNullOrWhiteSpace(Keyword), w => w.Name.Contains(Keyword)) .WhereIf(input.NhomDichVuId.HasValue, w => w.NhomDichVuId == input.NhomDichVuId) .WhereIf(input.IsActive.HasValue, w => w.IsActive == input.IsActive) join NhomDichVu in _danhMucNhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J1 from NhomDichVu in J1.DefaultIfEmpty() select new { DichVu, NhomDichVuName = NhomDichVu != null ? NhomDichVu.Name : "" }; var TotalCount = await query.CountAsync(); var PagedDichVu = await query.OrderBy(o => o.DichVu.Name).PageBy(input).ToListAsync(); var DichVus = new List <DanhMucDichVuDto>(); foreach (var item in PagedDichVu) { var DichVu = ObjectMapper.Map <DanhMucDichVuDto>(item.DichVu); DichVu.NhomDichVuName = item.NhomDichVuName; DichVus.Add(DichVu); } return(new PagedResultDto <DanhMucDichVuDto>( TotalCount, DichVus )); }
public async Task <GetInfoDto> GetInfo() { long userId = _abpSession.UserId.Value; //var user = await _userManager.GetUserByIdAsync(userId); var UserData = await(from User in _userRepository.GetAll().Where(w => w.Id == userId) join KhachHang in _khachHangRepository.GetAll() on User.Id equals KhachHang.UserId into J1 from KhachHang in J1.DefaultIfEmpty() select new { User, KhachHang.Address, KhachHang.DistrictId, KhachHang.ProvinceId }).FirstOrDefaultAsync(); if (UserData == null) { throw new UserFriendlyException(L("UserIsNotLogin")); } GetInfoDto result = ObjectMapper.Map <GetInfoDto>(UserData.User); result.ProfilePicture = UserData.User.ProfilePicture != null?Convert.ToBase64String(UserData.User.ProfilePicture) : ""; result.Address = UserData.Address; result.DistrictId = UserData.DistrictId; result.ProvinceId = UserData.ProvinceId; List <string> NhomDichVu = new List <string>(); string PhuTrach = ""; if (!UserData.User.IsCustomer) { NhomDichVu = await(from DmNhomDichVu in _nhomDichVuRepository.GetAll() join NvNhomDichVu in _nhanVienNhomDichVuRepository.GetAll() on DmNhomDichVu.Id equals NvNhomDichVu.NhomDichVuId where NvNhomDichVu.NhanVienId == UserData.User.Id select DmNhomDichVu.Name).ToListAsync(); var NvQuanHuyen = _nhanVienQuanHuyenRepository.GetAll().Where(w => w.NhanVienId == UserData.User.Id).Select(s => s.QuanHuyenId); var TinhThanhQuanHuyen = await(from NvTinhThanh in _nhanVienTinhThanhRepository.GetAll().Where(w => w.NhanVienId == UserData.User.Id) join DmTinhThanh in _tinhThanhRepository.GetAll() on NvTinhThanh.TinhThanhId equals DmTinhThanh.Id join DmQuanHuyen in _quanHuyenRepository.GetAll().Where(w => NvQuanHuyen.Contains(w.Id)) on DmTinhThanh.Id equals DmQuanHuyen.TinhThanhId into J1 from DmQuanHuyen in J1.DefaultIfEmpty() select new { TinhThanhName = DmTinhThanh.Name, QuanHuyenName = DmQuanHuyen.Name } into L1 group L1.QuanHuyenName by L1.TinhThanhName into G1 select new { TinhThanhName = G1.Key, QuanHuyenList = G1.Where(w => w != null).ToList() }).ToListAsync(); foreach (var item in TinhThanhQuanHuyen) { if (string.IsNullOrWhiteSpace(PhuTrach)) { PhuTrach = item.TinhThanhName; } else { PhuTrach += string.Format("; {0}", item.TinhThanhName); } PhuTrach += item.QuanHuyenList.Count > 0 ? ": " + string.Join(", ", item.QuanHuyenList) : ""; } if (UserData.User.TramDichVuId > 0) { result.TramDichVu = _tramDichVuRepository.GetAll().Where(w => w.Id == (int)UserData.User.TramDichVuId).Select(s => s.Name).FirstOrDefault(); } } result.ChuyenMon = NhomDichVu.Count > 0 ? string.Join("; ", NhomDichVu) : ""; result.PhuTrach = PhuTrach; return(result); }
public async Task <PagedResultDto <KhachHangDto> > GetAll(GetAllKhachHangInput input) { var query = from KhachHang in _khachHangRepository.GetAll() .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), w => w.Name.Contains(input.Filter) || w.PhoneNumber.Contains(input.Filter)) join TaiKhoan in _userRepository.GetAll() on KhachHang.UserId equals TaiKhoan.Id into J1 from TaiKhoan in J1.DefaultIfEmpty() join TinhThanh in _tinhThanhRepository.GetAll() on KhachHang.ProvinceId equals TinhThanh.Id into J3 from TinhThanh in J3.DefaultIfEmpty() join QuanHuyen in _quanHuyenRepository.GetAll() on KhachHang.DistrictId equals QuanHuyen.Id into J4 from QuanHuyen in J4.DefaultIfEmpty() select new { KhachHang, TaiKhoan.UserName, IsActive = TaiKhoan != null?TaiKhoan.IsActive.ToString() : "", TaiKhoan.EmailConfirmationCode, TinhThanhName = TinhThanh.Name, QuanHuyenName = QuanHuyen.Name }; var TotalCount = await query.CountAsync(); var PagedKhachHang = await query.OrderBy(o => o.KhachHang.Name).PageBy(input).ToListAsync(); var KhachHangs = new List <KhachHangDto>(); foreach (var item in PagedKhachHang) { var KhachHang = ObjectMapper.Map <KhachHangDto>(item.KhachHang); KhachHang.UserName = item.UserName; KhachHang.AddressFull = KhachHang.Address + (string.IsNullOrWhiteSpace(item.QuanHuyenName) ? "" : ", " + item.QuanHuyenName); KhachHang.AddressFull += string.IsNullOrWhiteSpace(item.TinhThanhName) ? "" : ", " + item.TinhThanhName; if (!string.IsNullOrWhiteSpace(item.IsActive)) { // Không active và không có email confirm code // => Đã active, đang bị lock if (item.IsActive == "False" && string.IsNullOrWhiteSpace(item.EmailConfirmationCode)) { KhachHang.IsActived = true; KhachHang.IsLocked = true; KhachHang.Status = "Đã khóa"; } // Không active và có email confirm code // => Đang chờ active, không bị lock else if (item.IsActive == "False" && !string.IsNullOrWhiteSpace(item.EmailConfirmationCode)) { KhachHang.IsActived = false; KhachHang.IsLocked = false; KhachHang.Status = "Chưa kích hoạt"; } // Có active, không quan tâm email confirm code // => Đang active, không bị lock else { KhachHang.IsActived = true; KhachHang.IsLocked = false; KhachHang.Status = "Đang hoạt động"; } } else { KhachHang.Status = "-"; } KhachHangs.Add(KhachHang); } return(new PagedResultDto <KhachHangDto>( TotalCount, KhachHangs )); }
public async Task <List <CongViecDto> > GetAll(DanhSachCongViecInput input) { var UserCache = await _globalCache.GetUserCache((long)AbpSession.UserId); if (UserCache.Id == 0) { return(new List <CongViecDto>()); } var query = from CongViec in _congViecRepository.GetAll() .WhereIf(input.TrangThaiIds.Length > 0, w => input.TrangThaiIds.ToList().Contains(w.TrangThaiId)) .WhereIf(UserCache.IsCustomer, w => w.KhachHangId == UserCache.CustomerId) .WhereIf(!UserCache.IsCustomer, w => w.NhanVienId == AbpSession.UserId) join DichVu in _dichVuRepository.GetAll() on CongViec.DichVuId equals DichVu.Id into J1 from DichVu in J1.DefaultIfEmpty() join NhomDichVu in _nhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J6 from NhomDichVu in J6.DefaultIfEmpty() join TramDichVu in _tramDichVuRepository.GetAll() on CongViec.TramDichVuId equals TramDichVu.Id into J5 from TramDichVu in J5.DefaultIfEmpty() join NhanVien in _nhanVienRepository.GetAll() on CongViec.NhanVienId equals NhanVien.Id into J2 from NhanVien in J2.DefaultIfEmpty() join TinhThanh in _tinhThanhRepository.GetAll() on CongViec.DiaChiTinhThanhId equals TinhThanh.Id into J3 from TinhThanh in J3.DefaultIfEmpty() join QuanHuyen in _quanHuyenRepository.GetAll() on CongViec.DiaChiQuanHuyenId equals QuanHuyen.Id into J4 from QuanHuyen in J4.DefaultIfEmpty() select new { CongViec, NhomDichVuId = NhomDichVu != null ? NhomDichVu.Id : 0, NhomDichVuName = NhomDichVu.Name, DichVuName = DichVu.Name, TramDichVuName = TramDichVu.Name, NhanVienName = NhanVien.Name, NhanVienPhone = NhanVien.PhoneNumber, TinhThanhName = TinhThanh.Name, QuanHuyenName = QuanHuyen.Name }; var CongViecs = await query.OrderBy(o => o.CongViec.NgayGioHen).Skip((input.Page - 1) * 10).Take(10).ToListAsync(); var CongViecDtos = new List <CongViecDto>(); foreach (var item in CongViecs) { var CongViec = ObjectMapper.Map <CongViecDto>(item.CongViec); if (item.NhomDichVuId > 0) { CongViec.NhomDichVuId = item.NhomDichVuId; } CongViec.NhomDichVuName = item.NhomDichVuName; CongViec.DichVuName = item.DichVuName; CongViec.TramDichVuName = item.TramDichVuName; CongViec.NhanVienName = item.NhanVienName; CongViec.NhanVienPhone = item.NhanVienPhone; CongViec.DiaChi += string.IsNullOrWhiteSpace(item.QuanHuyenName) ? "" : ", " + item.QuanHuyenName; CongViec.DiaChi += string.IsNullOrWhiteSpace(item.TinhThanhName) ? "" : ", " + item.TinhThanhName; CongViec.TrangThaiName = item.CongViec.TrangThaiId >= 0 && GlobalModel.TrangThaiCongViec.ContainsKey((int)item.CongViec.TrangThaiId) ? GlobalModel.TrangThaiCongViec[(int)item.CongViec.TrangThaiId] : ""; CongViec.Image1 = string.IsNullOrWhiteSpace(CongViec.Image1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image1); CongViec.Image2 = string.IsNullOrWhiteSpace(CongViec.Image2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image2); CongViec.Image3 = string.IsNullOrWhiteSpace(CongViec.Image3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image3); CongViec.ImageHoanThanh1 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh1); CongViec.ImageHoanThanh2 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh2); CongViec.ImageHoanThanh3 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh3); CongViec.ImageKhachHang1 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang1); CongViec.ImageKhachHang2 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang2); CongViec.ImageKhachHang3 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang3); CongViecDtos.Add(CongViec); } return(CongViecDtos); }
public async Task <string> Create(CreateYeuCauDto input) { var UserCache = await _globalCache.GetUserCache((long)AbpSession.UserId); if (UserCache.Id == 0 || !UserCache.IsCustomer) { throw new UserFriendlyException(L("UserIsNotCustomer")); } // Ghép chuỗi để có địa chỉ đầy đủ string Address = input.DiaChi; string QuanHuyenName = await _globalCache.GetQuanHuyenName(input.DiaChiTinhThanhId, input.DiaChiQuanHuyenId); Address += string.IsNullOrWhiteSpace(QuanHuyenName) ? "" : ", " + QuanHuyenName; string TinhThanhName = await _globalCache.GetTinhThanhName(input.DiaChiTinhThanhId); Address += string.IsNullOrWhiteSpace(TinhThanhName) ? "" : ", " + TinhThanhName; Address += ", Việt Nam"; var CongViec = ObjectMapper.Map <CongViec>(input); CongViec.KhachHangId = UserCache.CustomerId; CongViec.KhachHangName = UserCache.Name; CongViec.Location = await GlobalFunction.GetLongLatFromAddress(_globalCache.GetGoogleApiKey(), Address); CongViec.TrangThaiId = 0; CongViec.NgayYeuCau = DateTime.Now; CongViec.TimeId = string.Format("{0:yyyyMM}", CongViec.NgayYeuCau); // Tự động phân bổ công việc về Trạm var CongViecTheoTram = _congViecRepository.GetAll().Where(w => w.TramDichVuId > 0 && (w.TrangThaiId == (int)GlobalConst.TrangThaiCongViec.ChoPhanBo || w.TrangThaiId == (int)GlobalConst.TrangThaiCongViec.DaPhanBo || w.TrangThaiId == (int)GlobalConst.TrangThaiCongViec.DaNhan || w.TrangThaiId == (int)GlobalConst.TrangThaiCongViec.DangXuLy || w.TrangThaiId == (int)GlobalConst.TrangThaiCongViec.ChoLinhKien) ).GroupBy(g => g.TramDichVuId) .Select(s => new { TramDichVuId = s.Key, SoCongViec = s.Count() }); var query = from TramDichVu in _tramDichVuRepository.GetAll().Where(w => w.DiaChiTinhThanhId == input.DiaChiTinhThanhId || w.DiaChiQuanHuyenId == input.DiaChiQuanHuyenId) join CongViecTungTram in CongViecTheoTram on TramDichVu.Id equals CongViecTungTram.TramDichVuId into J1 from CongViecTungTram in J1.DefaultIfEmpty() select new { TramDichVu.Id, TramDichVu.DiaChiTinhThanhId, TramDichVu.DiaChiQuanHuyenId, SoCongViec = CongViecTungTram != null ? CongViecTungTram.SoCongViec : 0 }; var Trams = await query.ToListAsync(); if (Trams.Count > 0) { var TramPhanBo = Trams.Where(w => w.DiaChiQuanHuyenId == input.DiaChiQuanHuyenId).OrderBy(o => o.SoCongViec).FirstOrDefault(); if (TramPhanBo == null) { TramPhanBo = Trams.Where(w => w.DiaChiTinhThanhId == input.DiaChiTinhThanhId).OrderBy(o => o.SoCongViec).FirstOrDefault(); } if (TramPhanBo != null) { CongViec.TramDichVuId = TramPhanBo.Id; } } await _congViecRepository.InsertAsync(CongViec); return("OK"); }
public async Task <CongViecDto> Get(long Id) { var UserCache = await _globalCache.GetUserCache((long)AbpSession.UserId); if (UserCache.Id == 0) { throw new UserFriendlyException(L("UserIsNotLogin")); } var query = await(from CongViec in _congViecRepository.GetAll().Where(w => w.Id == Id) .WhereIf(UserCache.IsCustomer, w => w.KhachHangId == UserCache.CustomerId) .WhereIf(!UserCache.IsCustomer, w => w.NhanVienId == AbpSession.UserId) join DichVu in _dichVuRepository.GetAll() on CongViec.DichVuId equals DichVu.Id into J1 from DichVu in J1.DefaultIfEmpty() join NhomDichVu in _nhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J6 from NhomDichVu in J6.DefaultIfEmpty() join TramDichVu in _tramDichVuRepository.GetAll() on CongViec.TramDichVuId equals TramDichVu.Id into J2 from TramDichVu in J2.DefaultIfEmpty() join NhanVien in _nhanVienRepository.GetAll() on CongViec.NhanVienId equals NhanVien.Id into J3 from NhanVien in J3.DefaultIfEmpty() join TinhThanh in _tinhThanhRepository.GetAll() on CongViec.DiaChiTinhThanhId equals TinhThanh.Id into J4 from TinhThanh in J4.DefaultIfEmpty() join QuanHuyen in _quanHuyenRepository.GetAll() on CongViec.DiaChiQuanHuyenId equals QuanHuyen.Id into J5 from QuanHuyen in J5.DefaultIfEmpty() select new { CongViec, NhomDichVuId = NhomDichVu != null ? NhomDichVu.Id : 0, NhomDichVuName = NhomDichVu.Name, DichVuName = DichVu.Name, TramDichVuName = TramDichVu.Name, NhanVienName = NhanVien.Name, NhanVienPhone = NhanVien.PhoneNumber, TinhThanhName = TinhThanh.Name, QuanHuyenName = QuanHuyen.Name }).FirstOrDefaultAsync(); if (query == null) { throw new UserFriendlyException(L("CongViecIsNotFound")); } var result = ObjectMapper.Map <CongViecDto>(query.CongViec); if (query.NhomDichVuId > 0) { result.NhomDichVuId = query.NhomDichVuId; } result.NhomDichVuName = query.NhomDichVuName; result.DichVuName = query.DichVuName; result.TramDichVuName = query.TramDichVuName; result.NhanVienName = query.NhanVienName; result.NhanVienPhone = query.NhanVienPhone; result.DiaChi += string.IsNullOrWhiteSpace(query.QuanHuyenName) ? "" : ", " + query.QuanHuyenName; result.DiaChi += string.IsNullOrWhiteSpace(query.TinhThanhName) ? "" : ", " + query.TinhThanhName; result.TrangThaiName = query.CongViec.TrangThaiId >= 0 && GlobalModel.TrangThaiCongViec.ContainsKey((int)query.CongViec.TrangThaiId) ? GlobalModel.TrangThaiCongViec[(int)query.CongViec.TrangThaiId] : ""; result.Image1 = string.IsNullOrWhiteSpace(result.Image1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image1); result.Image2 = string.IsNullOrWhiteSpace(result.Image2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image2); result.Image3 = string.IsNullOrWhiteSpace(result.Image3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image3); result.ImageHoanThanh1 = string.IsNullOrWhiteSpace(result.ImageHoanThanh1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh1); result.ImageHoanThanh2 = string.IsNullOrWhiteSpace(result.ImageHoanThanh2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh2); result.ImageHoanThanh3 = string.IsNullOrWhiteSpace(result.ImageHoanThanh3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh3); result.ImageKhachHang1 = string.IsNullOrWhiteSpace(result.ImageKhachHang1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang1); result.ImageKhachHang2 = string.IsNullOrWhiteSpace(result.ImageKhachHang2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang2); result.ImageKhachHang3 = string.IsNullOrWhiteSpace(result.ImageKhachHang3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang3); // Lấy danh sách hạng mục công việc result.DanhSachHangMuc = await(from CongViecHangMuc in _congViecHangMucRepository.GetAll().Where(w => w.CongViecId == query.CongViec.Id) join DanhMucHangMuc in _hangMucRepository.GetAll() on CongViecHangMuc.HangMucId equals DanhMucHangMuc.Id select new CongViecHangMucDto { HangMucId = DanhMucHangMuc.Id, Name = DanhMucHangMuc.Name, DonViTinh = DanhMucHangMuc.DonViTinh, SoLuong = CongViecHangMuc.SoLuong, DonGia = CongViecHangMuc.DonGia, ThanhTien = CongViecHangMuc.ThanhTien }).ToListAsync(); // Tạm tính thành tiền của công việc bằng cách lấy tổng result.ThanhTien = result.PhuPhi ?? 0 + result.DanhSachHangMuc.Sum(s => s.ThanhTien); return(result); }