public OfferringDTO GetById([FromQuery] int id) { Offerring Offer = _repos.GetById(id); OfferringDTO OfferDTO = _mapper.Map <Offerring, OfferringDTO>(Offer); return(OfferDTO); }
//POST public OfferringDTO Create([FromBody] OfferringDTO offerring) { Offerring Offer = _repos.Create(offerring); OfferringDTO OfferDTO = _mapper.Map <Offerring, OfferringDTO>(Offer); return(OfferDTO); }
public bool Update(OfferringDTO putOfferring) { bool flag = true; if (IsUpdatable(putOfferring.Id)) { using (CarPoolContext context = new CarPoolContext()) { Offerring offer = context.Offerrings.FirstOrDefault(e => e.Id == putOfferring.Id); offer.Source = new Location() { Lattitude = putOfferring.Source.Lattitude, Longitude = putOfferring.Source.Longitude, LocationName = putOfferring.Source.LocationName }; offer.Destination = new Location() { Lattitude = putOfferring.Destination.Lattitude, Longitude = putOfferring.Destination.Longitude, LocationName = putOfferring.Destination.LocationName }; offer.CurrentLocation = new Location() { Lattitude = putOfferring.Source.Lattitude, Longitude = putOfferring.Source.Longitude, LocationName = putOfferring.Source.LocationName }; offer.Discount = putOfferring.Discount; offer.StartTime = putOfferring.StartTime; offer.TotalEarning = 0; offer.Vechicles.Capacity = putOfferring.Vehicle.Capacity; offer.Vechicles.NumberPlate = putOfferring.Vehicle.NumberPlate; offer.Vechicles.Type = (VehicleType)Enum.Parse(typeof(VehicleType), putOfferring.Vehicle.Type.ToString()); context.ViaPoints.RemoveRange(context.ViaPoints.Where(e => e.OfferId == offer.Id).ToList()); foreach (LocationDTO location in putOfferring.ViaPoints) { context.Add(new ViaPoints() { Location = new Location() { Lattitude = location.Lattitude, Longitude = location.Longitude, LocationName = location.LocationName }, OfferId = offer.Id }); } context.SaveChanges(); } flag = true; } else { flag = false; } return(flag); }
public bool Update(OfferringDTO putOfferring) { bool flag = true; if (IsUpdatable(putOfferring.Id)) { using (CarPoolContext context = new CarPoolContext()) { Offerring offer = context.Offerrings.Where(e => e.Id == putOfferring.Id).Single(); offer.Source = new Location() { Lattitude = putOfferring.Source.Lattitude, Longitude = putOfferring.Source.Longitude, LocationName = putOfferring.Source.LocationName }; offer.Destination = new Location() { Lattitude = putOfferring.Destination.Lattitude, Longitude = putOfferring.Destination.Longitude, LocationName = putOfferring.Destination.LocationName }; offer.CurrentLocation = new Location() { Lattitude = putOfferring.Source.Lattitude, Longitude = putOfferring.Source.Longitude, LocationName = putOfferring.Source.LocationName }; offer.Discount = putOfferring.Discount; offer.StartTime = putOfferring.StartTime; offer.TotalEarning = 0; context.ViaPoints.RemoveRange(context.ViaPoints.Where(e => e.OfferId == offer.Id).ToList()); foreach (LocationDTO location in putOfferring.ViaPoints) { context.Add(new ViaPoints() { Location = new Location() { Lattitude = location.Lattitude, Longitude = location.Longitude, LocationName = location.LocationName }, OfferId = offer.Id }); } context.SaveChanges(); } flag = true; } else { flag = false; } return(flag); }
public Offerring Create(OfferringDTO postOfferring) { Offerring offer = new Offerring { Active = true, Destination = new Location() { Lattitude = postOfferring.Destination.Lattitude, Longitude = postOfferring.Destination.Longitude, LocationName = postOfferring.Destination.LocationName }, Source = new Location() { Lattitude = postOfferring.Source.Lattitude, Longitude = postOfferring.Source.Longitude, LocationName = postOfferring.Source.LocationName }, CurrentLocation = new Location() { Lattitude = postOfferring.Source.Lattitude, Longitude = postOfferring.Source.Longitude, LocationName = postOfferring.Source.LocationName }, UserId = postOfferring.UserId, SeatsOffered = postOfferring.MaxOfferSeats, SeatsAvailable = postOfferring.MaxOfferSeats, Discount = postOfferring.Discount, PricePerKM = postOfferring.PricePerKM, StartTime = postOfferring.StartTime, Vechicles = new Vechicles() { Active = true, Capacity = postOfferring.Vehicle.Capacity, NumberPlate = postOfferring.Vehicle.NumberPlate, Type = (VehicleType)Enum.Parse(typeof(VehicleType), postOfferring.Vehicle.Type.ToString()) }, }; var offerring = _context.Offerrings.Add(offer).Entity; _context.SaveChanges(); foreach (LocationDTO point in postOfferring.ViaPoints) { _context.ViaPoints.Add(new ViaPoints { Location = new Location() { Lattitude = point.Lattitude, LocationName = point.LocationName, Longitude = point.Longitude }, OfferId = offerring.Id }); } _context.SaveChanges(); return(_context.Offerrings.Where(e => e.Id == offerring.Id).Include(e => e.ViaPoints).Include(e => e.Vechicles).Include(e => e.User).Single()); }
public bool Update([FromBody] OfferringDTO offerring) { return(_repos.Update(offerring)); }
//POST public Offerring Create([FromBody] OfferringDTO offerring) { return(_repos.Create(offerring)); }