Beispiel #1
0
        public async Task <IActionResult> IndexAction()
        {
            var results = await _repository.ToListAsync();

            var newRs = new List <ThanhPhanMeTronCan>();

            foreach (var item in results)
            {
                var thongTinMeTron = await _dbContext.Set <ThongTinMeTron>().FirstAsync(x => x.Id.Equals(item.ThongTinMeTronId));

                var mac = await _dbContext.Set <MAC>().FirstAsync(x => x.Id == thongTinMeTron.MacId);

                var vehicle = await _dbContext.Set <Vehicle>().FirstAsync(x => x.Id == thongTinMeTron.VehicleId);

                var hopDong = await _dbContext.Set <HopDong>().FirstAsync(x => x.Id == thongTinMeTron.HopDongId);

                item.ThongTinMeTron         = thongTinMeTron;
                item.ThongTinMeTron.MAC     = mac;
                item.ThongTinMeTron.Vehicle = vehicle;
                item.ThongTinMeTron.HopDong = hopDong;
                newRs.Add(item);
            }

            return(Ok(ApiResponse <List <ThanhPhanMeTronCan> > .ApiOk(newRs)));
        }
        public async Task <IActionResult> LoginAction([FromBody] LoginForm form)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(form.UserName);

                try
                {
                    var result = await _signInManager.PasswordSignInAsync(form.UserName, form.Password, form.RememberMe, lockoutOnFailure : false);

                    if (result.Succeeded)
                    {
                        return(Ok(ApiResponse <User> .ApiOk(user)));
                    }
                    else
                    {
                        return(Ok(ApiResponse <object> .ApiError(result)));
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            await Task.CompletedTask;

            return(Ok());
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateThanhPhanCanDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var thanhPhanCan = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            var thongTinMeTron = await _dbContext.Set <ThongTinMeTron>().FirstAsync(x => x.Id.Equals(thanhPhanCan.ThongTinMeTronId));

            // thanhPhanCan.ThongTinMeTronId = thongTinMeTron.Id;


            InputUpdateThanhPhanCanDto.UpdateEntity(dto, thanhPhanCan);
            _repository.Update(thanhPhanCan);
            await _dbContext.SaveChangesAsync();

            ConcreteService service = new ConcreteService(_dbContext);
            await service.CapnhatThanhPhanMeTronCan(thongTinMeTron);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <ThanhPhanMeTronCan> .ApiOk(thanhPhanCan)));
        }
Beispiel #4
0
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateTTMTDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var thongTinMeTron = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            var mac = await _dbContext.Set <MAC>().FirstAsync(x => x.Id == dto.MacId);

            var hopDong = await _dbContext.Set <HopDong>().FirstAsync(x => x.Id == dto.HopDongId);

            var vehicle = await _dbContext.Set <Vehicle>().FirstAsync(x => x.Id == dto.VehicleId);

            thongTinMeTron.MAC     = mac;
            thongTinMeTron.HopDong = hopDong;
            thongTinMeTron.Vehicle = vehicle;

            InputUpdateTTMTDto.UpdateEntity(dto, thongTinMeTron);
            _repository.Update(thongTinMeTron);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <ThongTinMeTron> .ApiOk(thongTinMeTron)));
        }
Beispiel #5
0
        public async Task <IActionResult> CreateAction(
            [FromBody] InputCreateTTMTDto dto,
            [FromServices] IHttpContextAccessor httpContext
            )
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            // httpContext.HttpContext.User.Identity.Name;
            var user = await _userManager.FindByNameAsync(httpContext.HttpContext.User.Identity.Name);


            // check thông tin mẻ trộn này đã được add hay chưa

            var find = await _dbContext.Set <ThongTinMeTron>().Where(x => x.VehicleId.Equals(dto.VehicleId) &&
                                                                     x.MacId.Equals(dto.MacId) &&
                                                                     x.HopDongId.Equals(dto.HopDongId) &&
                                                                     x.NgayTron.Equals(dto.NgayTron) &&
                                                                     x.KhoiLuong.Equals(dto.KhoiLuong))
                       .CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.NgayTron), "Thông tin mẻ trộn này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }

            // var mac = await _dbContext.Set<MAC>().FirstAsync(x => x.Id == dto.MacId);
            // var hopDong = await _dbContext.Set<HopDong>().FirstAsync(x => x.Id == dto.HopDongId);
            // var vehicle = await _dbContext.Set<Vehicle>().FirstAsync(x => x.Id == dto.VehicleId);

            // dto.MacId = mac;
            // dto.HopDongId = hopDong;
            // dto.VehicleId = vehicle;

            var newTTMT = InputCreateTTMTDto.ToEntity(dto);

            newTTMT.UserId = user.Id;
            await _dbContext.Set <ThongTinMeTron>().AddAsync(newTTMT);

            SaiSo saiSo = new SaiSo()
            {
                ThongTinMeTron   = newTTMT,
                ThongTinMeTronId = newTTMT.Id
            };
            await _dbContext.Set <SaiSo>().AddAsync(saiSo);

            ConcreteService service = new ConcreteService(_dbContext);
            await service.TaoMeTron(newTTMT);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <ThongTinMeTron> .ApiOk(newTTMT)));
        }
Beispiel #6
0
        public async Task <IActionResult> IndexAction()
        {
            // check biển số xe này đã được add hay chưa
            var results = await _repository.ToListAsync();

            return(Ok(ApiResponse <List <Vehicle> > .ApiOk(results)));
        }
Beispiel #7
0
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateMacDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var mac = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            InputUpdateMacDto.UpdateEntity(dto, mac);
            mac.MacCode = MacService.CreateMacCode(mac);

            // check biển số xe này đã được add hay chưa
            var find = await _dbContext.Set <MAC>()
                       .Where(x => !x.Id.Equals(dto.Id) && x.MacName.Equals(dto.MacName) && x.Tuoi.Equals(dto.Tuoi) && x.DoSut.Equals(dto.DoSut)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.MacName), "Mac này đã được tạo trên hệ thống");
            }

            _repository.Update(mac);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <MAC> .ApiOk(mac)));
        }
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateVatTuDto dto)
        {
            // check vật tư này đã được add hay chưa
            //var find = await _dbContext.Set<VatTu>()
            //   .Where(x => x.Name.Equals(dto.Name) && x.Supplier.Equals(dto.Supplier)).CountAsync();
            //if (find > 0)
            //{
            //    ModelState.AddModelError(nameof(dto.Name), "Vật tư này đã được tạo trên hệ thống");
            //}

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var vatTu = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            var loaiVattu = await _dbContext.Set <LoaiVatTu>()
                            .FirstOrDefaultAsync(x => x.Id == dto.LoaiVatTuId);

            if (loaiVattu != null)
            {
                dto.LoaiVatTu = loaiVattu;
            }
            InputUpdateVatTuDto.UpdateEntity(dto, vatTu);
            _repository.Update(vatTu);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <VatTu> .ApiOk(vatTu)));
        }
        public async Task <IActionResult> CreateAction([FromBody] InputCreateVatTuDto dto)
        {
            // check vật tư này đã được add hay chưa
            var find = await _dbContext.Set <VatTu>()
                       .Where(x => x.Name.Equals(dto.Name) && x.Supplier.Equals(dto.Supplier)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.Name), "Vật tư này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }
            var loaiVattu = await _dbContext.Set <LoaiVatTu>()
                            .FirstOrDefaultAsync(x => x.Id == dto.LoaiVatTuId);

            if (loaiVattu != null)
            {
                dto.LoaiVatTu = loaiVattu;
            }
            var newVatTu = InputCreateVatTuDto.ToEntity(dto);
            await _dbContext.Set <VatTu>().AddAsync(newVatTu);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <VatTu> .ApiOk(newVatTu)));
        }
        public async Task <IActionResult> CreateAction([FromBody] InputCreateHopDongDto dto)
        {
            // check hợp đồng này đã được add hay chưa

            var find = await _dbContext.Set <HopDong>()
                       .Where(x => x.TenHopDong.Equals(dto.TenHopDong) && x.ChuDauTu.Equals(dto.ChuDauTu) && x.NhaThau.Equals(dto.NhaThau) &&
                              x.CongTrinh.Equals(dto.CongTrinh))
                       .CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.TenHopDong), "Vật tư này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }

            var mac = await _dbContext.Set <MAC>()
                      .FirstAsync(x => x.Id == dto.MacId);

            var newHd = InputCreateHopDongDto.ToEntity(dto);
            await _dbContext.Set <HopDong>().AddAsync(newHd);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <HopDong> .ApiOk(newHd)));
        }
        public async Task <IActionResult> CreateAction(string roleName)
        {
            var find = await _roleManager.FindByNameAsync(roleName);

            // var find = await _dbContext.Set<Role>().Where(x => x.Name.Equals(dto.Name)).CountAsync();
            if (find != null)
            {
                ModelState.AddModelError(nameof(roleName), "Role này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }
            var newRole = new Role()
            {
                Name = roleName
            };

            var result = await _roleManager.CreateAsync(newRole);

            // await _dbContext.Set<Role>().AddAsync(newRole);
            // await _dbContext.SaveChangesAsync();
            if (result.Succeeded)
            {
                return(Ok(ApiResponse <Role> .ApiOk(newRole)));
            }
            return(Ok(ApiResponse <IdentityResult> .ApiOk(result)));
        }
Beispiel #12
0
        public async Task <IActionResult> DeleteAction(Guid id)
        {
            // check biển số xe này đã được add hay chưa
            var find = await _repository.Where(x => x.Id.Equals(id)).FirstAsync();

            _repository.Remove(find);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <string> .ApiOk("Xoá thành công")));
        }
        public async Task <IActionResult> DeleteAction(Guid Id)
        {
            var roleId = Id.ToString();
            var role   = await _roleManager.FindByIdAsync(roleId);

            if (role != null)
            {
                var result = await _roleManager.DeleteAsync(role);
            }
            return(Ok(ApiResponse <string> .ApiOk("Xoá thành công")));
        }
        public async Task <IActionResult> CheckLoginAction()
        {
            if (!_currentUser.IsAuthenticated)
            {
                return(Ok(ApiResponse <string> .ApiError("not authenticated")));
            }
            var user = await _userManager.FindByIdAsync(_currentUser.Id.ToString());

            var roles = await _userManager.GetRolesAsync(user);

            await Task.CompletedTask;

            return(Ok(ApiResponse <User> .ApiOk(user)));
        }
        public async Task <IActionResult> GetUserInRole(Guid roleId)
        {
            var userRole = await _dbContext.Set <UserRole>().Where(x => x.RoleId.Equals(roleId)).ToListAsync();

            var users = new List <User>();

            foreach (var item in userRole)
            {
                var user = await _dbContext.Set <User>().FirstAsync(x => x.Id.Equals(item.UserId));

                users.Add(user);
            }
            return(Ok(ApiResponse <List <User> > .ApiOk(users)));
        }
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateLoaiVatTuDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var vatTu = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            InputUpdateLoaiVatTuDto.UpdateEntity(dto, vatTu);
            _repository.Update(vatTu);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <LoaiVatTu> .ApiOk(vatTu)));
        }
        public async Task <IActionResult> CreateAction([FromBody] InputCreateUserDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }
            var newUser = InputCreateUserDto.ToEntity(dto);
            var result  = await _userManager.CreateAsync(newUser, "Abcdef@123");

            if (result.Succeeded)
            {
                return(Ok(ApiResponse <User> .ApiOk(newUser)));
            }
            return(Ok(ApiResponse <IdentityResult> .ApiError(result)));
        }
        public async Task <IActionResult> CreateUser()
        {
            var user = new User()
            {
                UserName = "******",
                Email    = "[email protected]/",
                FullName = "Le Minh Thuận"
            };
            var result = await _userManager.CreateAsync(user, "Abcdef@123");

            if (result.Succeeded)
            {
                return(Ok(ApiResponse <User> .ApiOk(user)));
            }
            return(Ok(ApiResponse <IdentityResult> .ApiError(result)));
        }
        public async Task <IActionResult> IndexAction()
        {
            var results = await _repository.ToListAsync();

            var newRs = new List <HopDong>();

            foreach (var item in results)
            {
                var mac = await _dbContext.Set <MAC>()
                          .FirstAsync(x => x.Id == item.MacId);

                item.MAC = mac;
                newRs.Add(item);
            }

            return(Ok(ApiResponse <List <HopDong> > .ApiOk(newRs)));
        }
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateHopDongDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var hopDong = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            var mac = await _dbContext.Set <MAC>()
                      .FirstAsync(x => x.Id == dto.MacId);

            InputUpdateHopDongDto.UpdateEntity(dto, hopDong);
            hopDong.MAC = mac;
            _repository.Update(hopDong);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <HopDong> .ApiOk(hopDong)));
        }
        public async Task <IActionResult> IndexAction()
        {
            var results = await _repository.ToListAsync();

            var newRs = new List <VatTu>();

            foreach (var item in results)
            {
                var mac = await _dbContext.Set <LoaiVatTu>()
                          .FirstAsync(x => x.Id == item.LoaiVatTuId);

                if (mac != null)
                {
                    item.LoaiVatTu = mac;
                }
                newRs.Add(item);
            }
            return(Ok(ApiResponse <List <VatTu> > .ApiOk(newRs)));
        }
Beispiel #22
0
        public async Task <IActionResult> CreateAction([FromBody] InputCreateMacDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }
            var newMac = InputCreateMacDto.ToEntity(dto);
            var find   = await _dbContext.Set <MAC>()
                         .Where(x => x.MacName.Equals(newMac.MacName) && x.Tuoi.Equals(newMac.Tuoi) && x.DoSut.Equals(newMac.DoSut)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(newMac.MacName), "Mac này đã được tạo trên hệ thống");
            }
            await _dbContext.Set <MAC>().AddAsync(newMac);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <MAC> .ApiOk(newMac)));
        }
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateRoleDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var dtoId = dto.Id.ToString();

            var role = await _roleManager.FindByIdAsync(dtoId);

            InputUpdateRoleDto.UpdateEntity(dto, role);
            var result = await _roleManager.UpdateAsync(role);

            // _repository.Update(role);
            // await _dbContext.SaveChangesAsync();
            if (result.Succeeded)
            {
                return(Ok(ApiResponse <IdentityResult> .ApiOk(result)));
            }
            return(Ok(ApiResponse <Role> .ApiOk(role)));
        }
Beispiel #24
0
        public async Task <IActionResult> CreateAction([FromBody] InputCreateVehicleDto dto)
        {
            // check biển số xe này đã được add hay chưa
            var find = await _dbContext.Set <Vehicle>().Where(x => x.SerialNumber.Equals(dto.SerialNumber)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.SerialNumber), "Biển số này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }

            var newVehicle = InputCreateVehicleDto.ToEntity(dto);
            await _dbContext.Set <Vehicle>().AddAsync(newVehicle);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <Vehicle> .ApiOk(newVehicle)));
        }
Beispiel #25
0
        public async Task <IActionResult> UpdateAction([FromBody] InputUpdateVehicleDto dto)
        {
            // check biển số xe này đã được add hay chưa
            var find = await _repository.Where(x => x.SerialNumber.Equals(dto.SerialNumber) && !x.Id.Equals(dto.Id)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.SerialNumber), "Biển số này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }

            var vehicle = await _repository.FirstAsync(x => x.Id.Equals(dto.Id));

            InputUpdateVehicleDto.UpdateEntity(dto, vehicle);
            _repository.Update(vehicle);
            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <Vehicle> .ApiOk(vehicle)));
        }
        public async Task <IActionResult> CreateAction([FromBody] InputCreateLoaiVatTuDto dto)
        {
            // check loại vật tư này đã được add hay chưa
            var find = await _repository
                       .Where(x => x.Name.Equals(dto.Name)).CountAsync();

            if (find > 0)
            {
                ModelState.AddModelError(nameof(dto.Name), "Vật tư này đã được tạo trên hệ thống");
            }

            if (!ModelState.IsValid)
            {
                return(Ok(ApiResponse <object> .ApiError(ModelState)));
            }

            var newVatTu = InputCreateLoaiVatTuDto.ToEntity(dto);
            await _dbContext.Set <LoaiVatTu>().AddAsync(newVatTu);

            await _dbContext.SaveChangesAsync();

            return(Ok(ApiResponse <LoaiVatTu> .ApiOk(newVatTu)));
        }
        public async Task <IActionResult> IndexAction()
        {
            var results = await _dbContext.Set <User>().ToListAsync();

            return(Ok(ApiResponse <List <User> > .ApiOk(results)));
        }
        public async Task <IActionResult> FilterAction([FromQuery] string start, [FromQuery] string end, [FromQuery] string macId, [FromQuery] string hdId)
        {
            // var results = await _repository.ToListAsync();
            DateTime?startDate;
            DateTime?endDate;
            Guid?    hopDongId;
            Guid?    macCode;

            //check hdid
            if (string.IsNullOrEmpty(hdId))
            {
                hopDongId = null;
            }
            else
            {
                hopDongId = Guid.Parse(hdId);
            }

            //check macid
            if (string.IsNullOrEmpty(macId))
            {
                macCode = null;
            }
            else
            {
                macCode = Guid.Parse(macId);
            }

            //check start
            if (string.IsNullOrEmpty(start))
            {
                startDate = null;
            }
            else
            {
                startDate = DateTime.Parse(start);
            }

            //check end
            if (string.IsNullOrEmpty(end))
            {
                endDate = null;
            }
            else
            {
                endDate = DateTime.Parse(end);
            }

            var queryable = _repository.AsQueryable();
            var newRs     = new List <SaiSo>();
            var results   = await _repository.ToListAsync();

            // if(startDate != null && endDate == null && macCode == null && hopDongId == null)
            // {
            //     results = await _repository.Where(x => x.ThongTinMeTron.NgayTron >= startDate).ToListAsync();
            // }
            // if(startDate == null && endDate != null && macCode == null && hopDongId == null)
            // {
            //     results = await _repository.Where(x => x.ThongTinMeTron.NgayTron <= endDate).ToListAsync();
            // }
            // if(startDate == null && endDate != null && macCode != null && hopDongId == null)
            // {
            //     results = await _repository.Where(x => (x.ThongTinMeTron.NgayTron <= endDate) && (x.ThongTinMeTron.MAC.MacCode.Equals(macCode))).ToListAsync();
            // }
            // if(startDate == null && endDate != null && macCode == null && hopDongId != null)
            // {
            //     results = await _repository.Where(x => (x.ThongTinMeTron.NgayTron <= endDate) && (x.ThongTinMeTron.HopDong.Id.Equals(hopDongId))).ToListAsync();
            // }
            if ((startDate != null && endDate != null) && endDate > startDate)
            {
                results = await _repository.Where(x => x.ThongTinMeTron.NgayTron >= startDate && x.ThongTinMeTron.NgayTron <= endDate).ToListAsync();
            }
            if (startDate != null && endDate == null)
            {
                results = await _repository.Where(x => x.ThongTinMeTron.NgayTron >= startDate).ToListAsync();
            }
            if (startDate == null && endDate != null)
            {
                results = await _repository.Where(x => x.ThongTinMeTron.NgayTron <= endDate).ToListAsync();
            }
            if (startDate == null && endDate == null)
            {
                results = await _repository.ToListAsync();
            }
            var find = results.Count();

            if (find == 0)
            {
                return(Ok(ApiResponse <ModelStateDictionary> .ApiError(ModelState)));
            }
            else
            {
                foreach (var item in results)
                {
                    // var find1 = await _dbContext.Set<ThongTinMeTron>().Where(x => x.Id.Equals(item.ThongTinMeTronId) && x.MAC.MacCode.Equals(macCode)).CountAsync();
                    var thongTinMeTron = await _dbContext.Set <ThongTinMeTron>().FirstAsync(x => x.Id.Equals(item.ThongTinMeTronId));

                    if (macCode == null && hopDongId != null)
                    {
                        if (thongTinMeTron.HopDongId.Equals(hopDongId))
                        {
                            newRs.Add(item);
                        }
                    }
                    if (macCode == null && hopDongId == null)
                    {
                        newRs.Add(item);
                    }
                    if (macCode != null && hopDongId != null)
                    {
                        var mac = await _dbContext.Set <MAC>().Where(x => x.Id.Equals(item.ThongTinMeTron.MacId)).FirstAsync();

                        item.ThongTinMeTron.MAC = mac;
                        // var findHopDong = await _dbContext.Set<ThongTinMeTron>().Where(x => x.HopDongId.Equals(hopDongId)).CountAsync();
                        if (item.ThongTinMeTron.MacId.Equals(macCode) && item.ThongTinMeTron.HopDongId.Equals(hopDongId))
                        {
                            newRs.Add(item);
                        }
                    }
                    if (macCode != null && hopDongId == null)
                    {
                        var mac = await _dbContext.Set <MAC>().Where(x => x.Id.Equals(item.ThongTinMeTron.MacId)).FirstAsync();

                        item.ThongTinMeTron.MAC = mac;
                        // var findMac = await _dbContext.Set<MAC>().Where(x => x.Id.Equals(item.ThongTinMeTron.MacId)).CountAsync();
                        // var findMac =  item.ThongTinMeTron.MAC.MacCode.Equals(macCode);
                        if (item.ThongTinMeTron.MacId.Equals(macCode))
                        {
                            newRs.Add(item);
                        }
                        // if(thongTinMeTron.MAC.MacCode.Equals(macCode))
                        // {
                        //     newRs.Add(item);
                        // }
                    }
                    // item.ThongTinMeTron = thongTinMeTron;
                    // newRs.Add(item);
                }
            }


            return(Ok(ApiResponse <List <SaiSo> > .ApiOk(newRs)));
        }
        public async Task <IActionResult> IndexAction()
        {
            var results = await _repository.ToListAsync();

            return(Ok(ApiResponse <List <Role> > .ApiOk(results)));
        }