public IHttpActionResult PutOrder(int id, Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order.OrderId) { return(BadRequest()); } db.Entry(order).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutBookedPlace(int id, BookedPlace bookedPlace) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bookedPlace.BookedPlaceId) { return(BadRequest()); } db.Entry(bookedPlace).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookedPlaceExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutTourStatus(int id, TourStatus tourStatus) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tourStatus.TourStatusId) { return(BadRequest()); } db.Entry(tourStatus).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TourStatusExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Save(ExtraAirCore.Models.EFModels.Client client) { using (var dbContext = new ExtraAirContext()) { var user = dbContext.Users.SingleOrDefault(x => x.Email == client.Email); if (user != null) { throw new Exception("User Exist!"); } dbContext.Clients.Add(client); dbContext.SaveChanges(); } }
public IHttpActionResult PutAirport(AirportDto airportDto) { var airport = db.Airports.Find(airportDto.AirportId); if (airport == null) { return(BadRequest()); } airport.Name = airport.Name != airportDto.Name ? airportDto.Name : airport.Name; airport.Address.Country = airport.Address.Country != airportDto.Country ? airportDto.Country : airport.Address.Country; airport.Address.Street = airport.Address.Street != airportDto.Street ? airportDto.Street : airport.Address.Street; airport.Address.StreetNumber = airport.Address.StreetNumber != Convert.ToInt32(airportDto.StreetNumber) ? Convert.ToInt32(airportDto.StreetNumber) : airport.Address.StreetNumber; airport.Address.City = airport.Address.City != airportDto.City ? airportDto.City : airport.Address.City; db.Entry(airport).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AirportExists(airportDto.AirportId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public TourDetailsDto Get(TourDetailsHelper helper) { using (var dbContext = new ExtraAirContext()) { var list1 = dbContext.TourDetailses.Where(x => x.TourId == helper.TourId && x.DateStart == helper.DateStart && x.DateFinish == helper.DateFinish).ToList(); foreach (var td in list1) { if (td.DatePushed != null && td.Temporary && DateTime.Now.Subtract(Convert.ToDateTime(td.DatePushed)).Minutes > 5) { dbContext.TourDetailses.Remove(td); dbContext.SaveChanges(); } } var list = list1.ToList().Select(x => MapHelper(x, helper.ComfortType)); var b = new List <BookedPoint>(); var economyPass = 0; var businessPass = 0; if (!list.Any()) { return(null); } foreach (var l in list) { b = b.Concat(l.BookedPoints).ToList(); economyPass = l.CurrentPassengerCount.CountOfEconomyPassenger > economyPass ? l.CurrentPassengerCount.CountOfEconomyPassenger : economyPass; businessPass += l.CurrentPassengerCount.CountOfBusinessPassenger > businessPass ? l.CurrentPassengerCount.CountOfBusinessPassenger : businessPass; } return(new TourDetailsDto { BookedPoints = b, CurrentPassengerCount = new CountPassengerDto { CountOfEconomyPassenger = economyPass, CountOfBusinessPassenger = businessPass } }); } }
public void PostAddress(AddressDto address) { using (var db = new ExtraAirContext()) { db.Addresses.Add(new ExtraAirCore.Models.EFModels.Address() { AddressId = address.AddressId, City = address.City, Country = address.Country, PostIndex = address.PostIndex, Street = address.Street, StreetNumber = address.StreetNumber }); db.SaveChanges(); } }
public async Task <IHttpActionResult> UploadFile(int id) { HttpRequestMessage request = Request; if (!request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } try { var currentUser = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); if (currentUser == null) { return(NotFound()); } if (!User.IsInRole(Roles.Client) && id != currentUser.UserId) { return(Content(HttpStatusCode.Forbidden, Messages.AccsesDenied)); } var streamProvider = new FilenameMultipartFormDataStreamProvider(ServerUploadFolder); await Request.Content.ReadAsMultipartAsync(streamProvider); var fileName = Path.GetFileName(streamProvider.FileData.Select(entry => entry.LocalFileName).First()); var user = db.Users.Find(id); if (user == null) { return(NotFound()); } user.ImagePath = "content/images/" + fileName; db.Entry(user).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok(ExtraAirCore.Constants.Path.WebApiPath + "content/images/" + fileName)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } var currentUser = db.Users.Find(id); currentUser.Birthday = currentUser.Birthday != user.Birthday ? user.Birthday : currentUser.Birthday; currentUser.LastName = currentUser.LastName != user.LastName ? user.LastName : currentUser.LastName; currentUser.FirstName = currentUser.FirstName != user.FirstName ? user.FirstName : currentUser.FirstName; currentUser.Phone = currentUser.Phone != user.Phone ? user.Phone : currentUser.Phone; if (user.Address != null && user.Address.AddressId == 0) { db.Addresses.Add(user.Address); db.SaveChanges(); currentUser.Address = user.Address; } else if (currentUser.Address != null) { currentUser.Address.City = currentUser.Address.City != user.Address.City ? user.Address.City : currentUser.Address.City; currentUser.Address.Country = currentUser.Address.Country != user.Address.Country ? user.Address.Country : currentUser.Address.Country; currentUser.Address.Street = currentUser.Address.Street != user.Address.Street ? user.Address.Street : currentUser.Address.Street; currentUser.Address.StreetNumber = currentUser.Address.StreetNumber != user.Address.StreetNumber ? user.Address.StreetNumber : currentUser.Address.StreetNumber; currentUser.Address.PostIndex = currentUser.Address.PostIndex != user.Address.PostIndex ? user.Address.PostIndex : currentUser.Address.PostIndex; } currentUser.IdCard = currentUser.IdCard != user.IdCard ? user.IdCard : currentUser.IdCard; db.Entry(currentUser).State = EntityState.Modified; db.Entry(currentUser).Property(x => x.ImagePath).IsModified = false; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }