public async Task <IActionResult> PutUser(int id, User user) { if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> PostBooking(Booking booking) { BookingAvailability bookingAvailability = _context.BookingAvailabilities.SingleOrDefault(d => d.BookingDate == booking.Booking_Date && d.DealerId == booking.DealerId); Dealer dealer = _context.Dealer.SingleOrDefault(d => d.Id == booking.DealerId); if (bookingAvailability == null) { BookingAvailability bookAvail = new BookingAvailability { BookingDate = booking.Booking_Date, DealerId = booking.DealerId, No_Of_Bookings = 1 }; booking.BookingStatus = "Open"; _context.BookingAvailabilities.Add(bookAvail); _context.Booking.Add(booking); await _context.SaveChangesAsync(); return(Ok(new ApiResponse(new { Success = true, msg = "Booking Done successfully", booking = booking }))); } else if (bookingAvailability.No_Of_Bookings < dealer.PerDay_DealingCapacity) { bookingAvailability.No_Of_Bookings += 1; booking.BookingStatus = "Open"; _context.Entry(bookingAvailability).State = EntityState.Modified; _context.Booking.Add(booking); await _context.SaveChangesAsync(); return(Ok(new ApiResponse(new { Success = true, msg = "Booking Done successfully", booking = booking }))); } else { return(NotFound(new NotFoundError("Booking Not available"))); } }
public async Task <IActionResult> PutBooking(int BookingId) { var booking = _context.Booking.SingleOrDefault(b => b.Id == BookingId); if (booking != null) { booking.BookingStatus = "Close"; _context.Entry(booking).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(BookingId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> EditUserRole(int id) { var user = _context.User.Find(id); if (id != user.Id) { return(BadRequest()); } user.Role = Role.Dealer; _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); Dealer dealer = new Dealer { Id = user.Id, Dealer_Name = user.user_name, Dealer_Email = user.User_Email, Dealer_Password = user.User_Password, Dealer_age = user.user_age, Dealer_gender = user.user_gender, Dealer_PhoneNo = user.user_phone, Role = Role.Dealer, PerDay_DealingCapacity = 5 }; _context.Dealer.Add(dealer); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(Ok(new ApiResponse(new { Success = true, Message = "Role changed successfully" }))); }
public async Task <IActionResult> PutPG(int id, PG pG) { if (id != pG.Id) { return(BadRequest()); } var ExistingPgImages = _IPgImagesRepository.GetPgImages(pG); var ExistingPgFacilities = _IPgFacilityRepository.GetPgFacilities(pG); //Edit Address Address addr = pG.Pg_Address; _context.Entry(addr).State = EntityState.Modified; //For editing Images foreach (var image in ExistingPgImages) { if (!pG.PgImages.Any(c => c.Image_Url == image.Image_Url)) { _context.PgImages.Remove(image); Console.WriteLine("Image removed"); } } foreach (var image in pG.PgImages) { var existingImage = ExistingPgImages.FirstOrDefault(x => x.Image_Url == image.Image_Url); if (existingImage != null) { Console.WriteLine("Images exist"); } else { // Insert child var PgImage = new PgImage { PGId = pG.Id, Image_Url = image.Image_Url }; _context.PgImages.Add(PgImage); Console.WriteLine("New Image added"); } } //for Editing Facility foreach (var facility in ExistingPgFacilities) { if (!pG.Facilities.Any(c => c.Facility_Name == facility.Facility_Name)) { _context.Facilities.Remove(facility); Console.WriteLine("facility removed"); } } foreach (var facility in pG.Facilities) { var existingFacility = ExistingPgFacilities.FirstOrDefault(x => x.Facility_Name == facility.Facility_Name); if (existingFacility != null) { Console.WriteLine("Facility exist"); } else { // Insert child var PgFacility = new Facility { PGId = pG.Id, Facility_Name = facility.Facility_Name }; _context.Facilities.Add(PgFacility); Console.WriteLine("New Facility added"); } } _context.Entry(pG).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PGExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }