public JsonResult gastationFillter(string data) { JavaScriptSerializer json_serializer = new JavaScriptSerializer(); dynamic queryData = json_serializer.DeserializeObject(data); string queryGasName = queryData["gasName"]; string querygasTpye = queryData["gasType"]; string queryDistrict = queryData["districtID"]; int queryPage = Convert.ToInt32(queryData["selectPage"]); // Dung để kiểm tra xem có tồn tại gastype hay không. bool checkType(string qr, List <DataAccess.Models.GasStationGasType> gt) { foreach (var item in gt) { if (qr.Contains(item.GasType)) { return(true); } } return(false); } //Fillter theo các điều kiện truyền vào var gasStationsN = _gasStationRepository.GetAll().Where(x => (queryGasName != null ? x.GasStationName.ToLowerInvariant().Contains(queryGasName) :true) && (querygasTpye != null ? checkType(querygasTpye, x.GasStationGasType.ToList()): true) && (queryDistrict != null ? x.District == (long)Convert.ToDouble(queryDistrict): true) ); countPage = gasStationsN.Count(); var gasStations = gasStationsN.Skip((queryPage - 1) * 10).Take(10).ToList(); List <GasStationVM> result = new List <GasStationVM>(); //Add gasstartion vào bên trong result foreach (var item in gasStations) { GasStationVM gasStationVM = new GasStationVM(); gasStationVM.GasStationName = item.GasStationName; int count = 0; foreach (var type in item.GasStationGasType) { if (count == 0) { gasStationVM.GasType += _mTypeRepository.getTypeText(type.GasType, 3); count++; } gasStationVM.GasType += ", " + _mTypeRepository.getTypeText(type.GasType, 3); } gasStationVM.GasStationId = item.GasStationId; gasStationVM.DistrictName = _districtRepository.FindById(item.District).DistrictName; gasStationVM.Longitude = item.Longitude; gasStationVM.Latitude = item.Latitude; gasStationVM.Rating = _mTypeRepository.getTypeText(item.Rating, 4); result.Add(gasStationVM); } return(Json(result)); }
public ActionResult Detail(long Id) { Models.FeedbackVM feedbackVM = new Models.FeedbackVM(); if (Id.ToString() == null) { return(RedirectToAction("Error", "Error")); } DataAccess.Models.GasStation gasStation = new DataAccess.Models.GasStation(); gasStation = _gasStationRepository.FindById(Id); if (gasStation == null) { return(RedirectToAction("NotFound", "Error")); } feedbackVM.GasStationName = gasStation.GasStationName; List <DataAccess.Models.GasStationGasType> listgasType = new List <DataAccess.Models.GasStationGasType>(); listgasType = _gasStationGasTypeRepository.GetAll().Where(x => x.GasStationId == Id).ToList(); foreach (var item in listgasType) { if (feedbackVM.GasType == null) { feedbackVM.GasType += _mTpyeRepository.getTypeText(item.GasType, 3); } else { feedbackVM.GasType += ", " + _mTpyeRepository.getTypeText(item.GasType, 3); } } feedbackVM.GasAddress = gasStation.Address + ", " + _districtRepository.FindById(gasStation.District).DistrictName; feedbackVM.OpenTime = gasStation.OpeningTime; feedbackVM.Rating = _mTpyeRepository.getTypeText(gasStation.Rating, 4); ViewBag.countPage = _feedbackRepository.GetAll().Where(x => x.GasStationId == Id).Count(); return(View(feedbackVM)); }
/// <summary> /// Get Address object and validate if department, province and district are valid /// </summary> /// <param name="idDepartment">Id Department</param> /// <param name="idDistrict">Id District</param> /// <param name="idProvince">Id Province</param> /// <returns>Address with names</returns> private Address GetAddressName(string idDepartment, string idDistrict, string idProvince) { var department = _departmentRepository.FindById(idDepartment); var district = _districtRepository.FindById(idDistrict); var province = _provinceRepository.FindById(idProvince); //if not found a department, then is invalid if (department == null) { throw new AppException("Department is not valid."); } //if not found a district, then is invalid if (district == null) { throw new AppException("District is not valid."); } //if not found a province, then is invalid if (province == null) { throw new AppException("Province is not valid."); } //Province doesn't belong department if (province.IdDepartment != department.Id) { throw new AppException("Province doesn't belong to selected department"); } //District doesn't belong province if (province.Id != district.IdProvince) { throw new AppException("District doesn't belong to selected province"); } return(new Address { Department = department.Name, District = district.Name, Province = province.Name }); }
public async Task <GasStationResul> GetAllGasStations([FromBody] Request request) { GasStationResul gasStationResul = new GasStationResul(); List <GasStaionMV> gasStationMVs = new List <GasStaionMV>(); List <GasStation> gasStations = await _gasStationRepository.GetAsyncAllGasStationWithQuery(request.GasName, request.District, request.GasTypes); gasStationResul.Count = gasStations.Count(); List <GasStation> gasStationsResult = gasStations.Skip((request.Page - 1) * 10).Take(10).ToList(); foreach (var gasStation in gasStationsResult) { GasStaionMV gasStationMV = new GasStaionMV(); gasStationMV.GasStationId = gasStation.GasStationId; gasStationMV.GasStationName = gasStation.GasStationName; gasStationMV.Address = gasStation.Address; gasStationMV.District = _districtRepository.FindById(gasStation.District); gasStationMV.OpeningTime = gasStation.OpeningTime; gasStationMV.Longitude = gasStation.Longitude; gasStationMV.Latitude = gasStation.Latitude; Rating rating = new Rating(); rating.Code = gasStation.Rating; rating.Name = _mTypeRepository.getTypeText(gasStation.Rating, 4); gasStationMV.Rating = rating; List <ModelsViews.Type> types = new List <ModelsViews.Type>(); foreach (var gastype in gasStation.GasStationGasType) { ModelsViews.Type type = new ModelsViews.Type(); type.GasTypeCode = gastype.GasType; type.GasTypeName = _mTypeRepository.getTypeText(gastype.GasType, 3); types.Add(type); } gasStationMV.Types = types; gasStationMVs.Add(gasStationMV); } gasStationResul.GasStaionMVs = gasStationMVs; return(gasStationResul); }
public async Task <AccountResponse> SaveAsync(AccountFactory account) { try { AccountFactory accountFactory = null; bool result = account.AccountType.Equals("Musician"); if (result == true) { accountFactory = new MusicianFactory(); } else { accountFactory = new OrganizerFactory(); } Account newAccount = accountFactory.GetAccount(); newAccount.FirstName = account.FirstName; newAccount.LastName = account.LastName; newAccount.Phone = account.Phone; newAccount.PersonalWeb = account.PersonalWeb; newAccount.BirthDate = account.BirthDate; newAccount.User = account.User; newAccount.RegisterDate = DateTime.Now; newAccount.AccountType = account.AccountType; int id = account.DistrictId; newAccount.District = await _districtRepository.FindById(id); await _accountRepository.AddAsync(newAccount); await _unitOfWork.CompleteAsync(); return(new AccountResponse(newAccount)); } catch (Exception ex) { return(new AccountResponse($"An error ocurred while saving the account: {ex.Message}")); } }
public District GetById(int districtId) { return(_districtRepository.FindById(districtId)); }