public async Task <Response> UpdateTransporter(Guid id, TransporterViewModel transporter) { var endpoint = baseurl + id; var response = await PutAsync <TransporterViewModel>(endpoint, new TransporterViewModel { Address = transporter.Address, Email = transporter.Email, Name = transporter.Name, Telephone = transporter.Telephone, TransporterId = transporter.TransporterId }); if (!response.IsSuccessStatusCode) { if (response.Content != null) { var errorMsg = await response.Content.ReadAsStringAsync(); return(Response.Unsuccesfull(response, errorMsg)); } return(Response.Unsuccesfull(response, response.ReasonPhrase)); } return(Response.Succes()); }
public async Task <IActionResult> OnPostDelete(TransporterViewModel transporterViewModel) { var result = await _transporterDataService.DeleteTransporter(TransporterViewModel.TransporterId); ResponseOkMessage = "Transportøren er slettet korrekt"; return(new RedirectToPageResult("./Transporters")); }
public async Task <Response> CreateTransporter(TransporterViewModel _transporter) { var response = await PostAsync <TransporterViewModel>(baseurl, _transporter); if (!response.IsSuccessStatusCode) { if (response.Content != null) { var errorMessage = await response.Content.ReadAsStringAsync(); return(Response.Unsuccesfull(response, errorMessage)); } return(Response.Unsuccesfull(response, response.ReasonPhrase)); } return(Response.Succes()); }
public async Task <IActionResult> OnPostRemoveSupplier(Guid ActiveSelectedSupplier, TransporterViewModel transporterViewModel) { if (ActiveSelectedSupplier.Equals(Guid.Empty)) { return(new RedirectToPageResult("", new { ok = transporterViewModel.TransporterId })); } var result = await _transporterDataService.RemoveSupplierFromTransporter(new RemoveSupplierFromTransporterCommand { SupplierId = ActiveSelectedSupplier, TransporterId = transporterViewModel.TransporterId }); return(new RedirectToPageResult("", new { ok = transporterViewModel.TransporterId })); }
public async Task <IActionResult> OnPostAddSupplier(Guid SelectedSupplier, TransporterViewModel transporterViewModel) { if (SelectedSupplier.Equals(Guid.Empty)) { ResponseFailMessage = "Der skete en fejl"; return(new RedirectToPageResult("", new { ok = transporterViewModel.TransporterId })); } await _transporterDataService.AddSupplierToTransporter(new AddSupplierToTransporterCommand { SupplierId = SelectedSupplier, TransporterId = transporterViewModel.TransporterId }); ResponseOkMessage = "Kunden er nu tilføjet korrekt"; return(new RedirectToPageResult("", new { ok = transporterViewModel.TransporterId })); }
public ActionResult Transporters(string from, string to) { string fromPlaceJson = PlaceDetails(from); string fromCityName = ((JObject.Parse(fromPlaceJson)["results"] as JArray)[0]["address_components"] as JArray).SingleOrDefault(x => x.ToString().Contains("administrative_area_level_1"))["short_name"].ToString().Split(' ')[0]; string fromFullName = ((JObject.Parse(fromPlaceJson)["results"] as JArray)[0])["formatted_address"].ToString(); string fromLat = (JObject.Parse(fromPlaceJson)["results"] as JArray)[0]["geometry"]["location"]["lat"].ToString(); string fromLng = (JObject.Parse(fromPlaceJson)["results"] as JArray)[0]["geometry"]["location"]["lng"].ToString(); string toPlaceJson = PlaceDetails(to); string toCityName = ((JObject.Parse(toPlaceJson)["results"] as JArray)[0]["address_components"] as JArray).SingleOrDefault(x => x.ToString().Contains("administrative_area_level_1"))["short_name"].ToString().Split(' ')[0]; string toFullName = ((JObject.Parse(toPlaceJson)["results"] as JArray)[0])["formatted_address"].ToString(); string toLat = (JObject.Parse(toPlaceJson)["results"] as JArray)[0]["geometry"]["location"]["lat"].ToString(); string toLng = (JObject.Parse(toPlaceJson)["results"] as JArray)[0]["geometry"]["location"]["lng"].ToString(); int dist = GetDistance(from, to); var transporters = db.Transporters.ToList().Where(x => x.IsAvailable(from, true, fromCityName) && x.IsAvailable(to, false, toCityName) && x.MinimumDistance <= dist && x.MaximumDistance >= dist).ToList(); var result = new SearchResultViewModel(); result.Distance = dist; result.From = new PlaceViewModel() { Id = from, Name = fromFullName, Lat = fromLat, Lng = fromLng }; result.To = new PlaceViewModel() { Id = to, Name = toFullName, Lat = toLat, Lng = toLng }; foreach (var item in transporters) { var transporter = new TransporterViewModel(); transporter.Id = item.Id; transporter.Plate = item.Plate; transporter.PassengerCapacity = item.PassengerCount; transporter.Price = dist * item.PricePerKilometer; result.Transporters.Add(transporter); } return(View(result)); }
public async Task <IActionResult> OnPostUpdate(TransporterViewModel transporterViewModel) { if (!ModelState.IsValid) { return(Page()); } var result = await _transporterDataService.UpdateTransporter(transporterViewModel.TransporterId, transporterViewModel); if (!result.IsSuccesfull) { return(new RedirectToPageResult("Error")); } ResponseOkMessage = "Opdatering af transportør var vellykket"; return(new RedirectToPageResult("./Transporters")); }
public async Task <ApiResult <TransporterViewModel> > GetById(int id) { var result = await _context.Transporters.FindAsync(id); if (result == null) { return(new ApiErrorResult <TransporterViewModel>("Đơn vị vận chuyển này không tồn tại")); } var transporter = new TransporterViewModel() { create_at = result.create_at, name = result.name, isActive = result.isActive, id = result.id, update_at = result.update_at, image = result.image, link = result.link }; return(new ApiSuccessResult <TransporterViewModel>(transporter)); }
public async Task <ActionResult <TransporterViewModel> > GetByIdAsync(int id) { var transporter = await _db.Transporters.FindAsync(id); if (transporter == null) { return(NotFound()); } var passengerIds = (from passenger in _db.Passengers where passenger.TransporterId == transporter.Id select passenger.Id).ToList(); var transporterViewModel = new TransporterViewModel { Id = transporter.Id, Name = transporter.Name, Passengers = passengerIds }; return(Ok(transporterViewModel)); }
public async Task <ActionResult <List <TransporterViewModel> > > GetAllAsync() { var transporters = await _db.Transporters.AsNoTracking().ToListAsync(); var transporterViewModels = new List <TransporterViewModel>(); foreach (var transporter in transporters) { var passengerIds = (from passenger in _db.Passengers where passenger.TransporterId == transporter.Id select passenger.Id).ToList(); var transporterViewModel = new TransporterViewModel { Id = transporter.Id, Name = transporter.Name, Passengers = passengerIds }; transporterViewModels.Add(transporterViewModel); } return(Ok(transporterViewModels)); }
public ActionResult ReserveTransporter(int id) { ViewBag.fromId = (TempData["from"] as PlaceViewModel).Id; ViewBag.toId = (TempData["to"] as PlaceViewModel).Id; ViewBag.fromName = (TempData["from"] as PlaceViewModel).Name; ViewBag.toName = (TempData["to"] as PlaceViewModel).Name; ViewBag.FromLat = (TempData["from"] as PlaceViewModel).Lat; ViewBag.FromLng = (TempData["from"] as PlaceViewModel).Lng; ViewBag.ToLat = (TempData["to"] as PlaceViewModel).Lat; ViewBag.ToLng = (TempData["to"] as PlaceViewModel).Lng; var item = db.Transporters.Find(id); var transporter = new TransporterViewModel(); transporter.Plate = item.Plate; transporter.Brand = item.Brand; transporter.Model = item.Model; transporter.WorkingHours = item.WorkingHours; transporter.BaggageCapacity = item.TotalBaggageCapacity; transporter.PassengerCapacity = item.PassengerCount; transporter.SeatSchema = item.SeatSchema; return(View(transporter)); }
public ActionResult TransporterDetails(int id, string from, string to, string from_name, string to_name, string from_lat, string from_lng, string to_lat, string to_lng) { ViewBag.From = from; ViewBag.To = to; ViewBag.FromName = from_name; ViewBag.ToName = to_name; ViewBag.FromLat = from_lat; ViewBag.FromLng = from_lng; ViewBag.ToLat = to_lat; ViewBag.ToLng = to_lng; var item = db.Transporters.Find(id); var transporter = new TransporterViewModel(); transporter.Plate = item.Plate; transporter.Brand = item.Brand; transporter.Model = item.Model; transporter.WorkingHours = item.WorkingHours; transporter.BaggageCapacity = item.TotalBaggageCapacity; transporter.PassengerCapacity = item.PassengerCount; transporter.SeatSchema = item.SeatSchema; return(PartialView(transporter)); }
public async Task <ActionResult <TransporterViewModel> > UpdatePassengerAsync(int id, TransporterViewModel transporterViewModel) { if (id != transporterViewModel.Id) { return(BadRequest()); } var transporter = await _db.Transporters.FindAsync(id); if (transporter == null) { return(NotFound()); } ICollection <Passenger> passengers = new List <Passenger>(); foreach (var passengerId in transporterViewModel.Passengers) { var passenger = await _db.Passengers.FindAsync(passengerId); if (passenger != null) { passengers.Add(passenger); } } transporter.Passengers = passengers; _db.Entry(transporter).State = EntityState.Modified; await _db.SaveChangesAsync(); return(Ok(transporterViewModel)); }
public TransporterViewModel GetTransporterViewModel(int id) { TransporterViewModel Transporterviewmodel = (from b in db.Transporter join bus in db.BusinessEntity on b.PersonID equals bus.PersonID into BusinessEntityTable from BusinessEntityTab in BusinessEntityTable.DefaultIfEmpty() join p in db.Persons on BusinessEntityTab.PersonID equals p.PersonID into PersonTable from PersonTab in PersonTable.DefaultIfEmpty() join pa in db.PersonAddress on b.PersonID equals pa.PersonId into PersonAddressTable from PersonAddressTab in PersonAddressTable.DefaultIfEmpty() join ac in db.LedgerAccount on b.PersonID equals ac.PersonId into AccountTable from AccountTab in AccountTable.DefaultIfEmpty() where b.PersonID == id select new TransporterViewModel { PersonId = b.PersonID, Name = PersonTab.Name, Suffix = PersonTab.Suffix, Code = PersonTab.Code, Phone = PersonTab.Phone, Mobile = PersonTab.Mobile, Email = PersonTab.Email, Address = PersonAddressTab.Address, CityId = PersonAddressTab.CityId, Zipcode = PersonAddressTab.Zipcode, TdsCategoryId = BusinessEntityTab.TdsCategoryId, TdsGroupId = BusinessEntityTab.TdsGroupId, IsActive = PersonTab.IsActive, LedgerAccountGroupId = AccountTab.LedgerAccountGroupId, CreatedBy = PersonTab.CreatedBy, CreatedDate = PersonTab.CreatedDate, PersonAddressID = PersonAddressTab.PersonAddressID, AccountId = AccountTab.LedgerAccountId, ImageFileName = PersonTab.ImageFileName, ImageFolderName = PersonTab.ImageFolderName } ).FirstOrDefault(); var PersonRegistration = (from pp in db.PersonRegistration where pp.PersonId == id select new { PersonRegistrationId = pp.PersonRegistrationID, RregistrationType = pp.RegistrationType, RregistrationNo = pp.RegistrationNo }).ToList(); if (PersonRegistration != null) { foreach (var item in PersonRegistration) { if (item.RregistrationType == PersonRegistrationType.PANNo) { Transporterviewmodel.PersonRegistrationPanNoID = item.PersonRegistrationId; Transporterviewmodel.PanNo = item.RregistrationNo; } if (item.RregistrationType == PersonRegistrationType.ServiceTaxNo) { Transporterviewmodel.PersonRegistrationServiceTaxNoID = item.PersonRegistrationId; Transporterviewmodel.ServiceTaxNo = item.RregistrationNo; } } } return(Transporterviewmodel); }