public async Task <Hotel> Add(Hotel hotel) { _context.HotelTable.Add(hotel); await _context.SaveChangesAsync(); return(hotel); }
public async Task <ActionResult <IEnumerable <RoomFacility> > > Post([FromBody] RoomFacility roomFacility) { context.RoomFacilities.Add(roomFacility); await context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = roomFacility.RoomFacilityId }, roomFacility)); }
public async Task <ActionResult <IEnumerable <Booking> > > Post([FromBody] Booking ctr) { _context.Bookings.Add(ctr); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = ctr.BookingId }, ctr)); }
public async Task <ActionResult <IEnumerable <HotelType> > > Post([FromBody] HotelType hotelType) { context.HotelTypes.Add(hotelType); await context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = hotelType.HotelTypeId }, hotelType)); }
public async Task <IActionResult> PutPayment([FromRoute] int id, [FromBody] Payment payment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != payment.PaymentId) { return(BadRequest()); } _context.Entry(payment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <IEnumerable <Customer> > > Post([FromBody] Customer ctr) { _context.Customers.Add(ctr); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = ctr.CustomerId }, ctr)); }
public async Task <ActionResult <IEnumerable <UserDetail> > > Post([FromBody] UserDetail hotelRoom) { context.UserDetails.Add(hotelRoom); await context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = hotelRoom.UserId }, hotelRoom)); }
public async Task <IActionResult> Post([FromBody] ConsumerDataDTO body) { string id = User.Claims.First(x => x.Type == "UserID").Value; string role = auth.Users.FirstOrDefault(x => x.Id == id).Role; if (role == "Dispatcher") { Consumer temp = new Consumer() { Name = body.Name, Surname = body.Surname, Phone = body.Phone, Type = body.Type, Street = data.Streets.FirstOrDefault(x => x.Name == body.Street) }; await data.Consumers.AddAsync(temp); await data.SaveChangesAsync(); return(Ok()); } else { return(Unauthorized()); } }
public async Task <IActionResult> Post([FromBody] RoomFacility roomFacility) { if (!ModelState.IsValid) { return(BadRequest()); } else { try { _context.RoomFacilities.Add(roomFacility); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = roomFacility.RoomFacilityId }, roomFacility)); } catch (Exception) { return(BadRequest()); } } }
public async Task <IActionResult> Post([FromBody] HotelType hotelType) { if (!ModelState.IsValid) { return(BadRequest()); } else { try { _context.HotelTypes.Add(hotelType); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = hotelType.HotelTypeId }, hotelType)); } catch (Exception) { return(BadRequest()); } } }
public async Task <IActionResult> Post([FromBody] DeviceDTO body) { Device device = new Device(); device.Type = body.Type; device.Name = body.Name; device.Street = data.Streets.FirstOrDefault(x => x.Name == body.Street); data.Devices.Add(device); await data.SaveChangesAsync(); return(Ok()); }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordKey; CreatePasswordHash(password, out passwordHash, out passwordKey); user.Password = passwordHash; user.PasswordKey = passwordKey; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <IActionResult> Post([FromBody] SafeteyDocDTO body) { // string id = User.Claims.First(x => x.Type == "UserID").Value; // string role = authentication.Users.FirstOrDefault(x => x.Id == id).Role; if (body.Role == "Dispatcher") { SafetyDoc sDoc = new SafetyDoc(); sDoc.Type = body.SafetyDoc.Type; // sDoc.WorkPlan = data.WorkPlans.FirstOrDefault(x => x.Id == body.SafetyDoc.WorkPlanId); sDoc.Status = body.SafetyDoc.Status; sDoc.UserID = body.Id; sDoc.Details = body.SafetyDoc.Details; sDoc.Notes = body.SafetyDoc.Notes; sDoc.DateCreated = DateTime.Now; sDoc.OperationsCompleted = body.SafetyDoc.OperationsCompleted; sDoc.TagsRemoved = body.SafetyDoc.TagsRemoved; sDoc.GroundingRemoved = body.SafetyDoc.GroundingRemoved; sDoc.Ready = body.SafetyDoc.Ready; foreach (DeviceDTO item in body.Devices) { await data.SafetyDocsDevices.AddAsync(new SafetyDocDevice { SafetyDoc = sDoc, Device = data.Devices.FirstOrDefault(x => x.Name == item.Name) }); } await data.SafetyDocs.AddAsync(sDoc); await data.SaveChangesAsync(); return(Ok()); } else { return(Unauthorized()); } }
public async Task <IActionResult> Post([FromBody] Call2DTO body) { Call call = new Call(); call.Comment = body.Call.Comment; call.Reason = body.Call.Reason; call.Hazard = body.Call.Hazard; call.Street = data.Streets.FirstOrDefault(x => x.Name == body.Call.Street); call.UserID = body.Id; data.Calls.Add(call); await data.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Post([FromBody] PlanDTO body) { string id = User.Claims.First(x => x.Type == "UserID").Value; string role = auth.Users.FirstOrDefault(x => x.Id == id).Role; if (role == "Dispatcher") { WorkPlan temp = new WorkPlan { Type = body.Plan.Type, Status = body.Plan.Status, WorkOrder = data.WorkOrders.FirstOrDefault(x => x.Id == body.Plan.WorkOrderId), StartTime = body.Plan.StartTime, EndTime = body.Plan.EndTime, UserID = id, Purpose = body.Plan.Purpose, Notes = body.Plan.Notes, Company = body.Plan.Company, DateCreated = DateTime.Now, Crew = data.Crews.FirstOrDefault(x => x.Id == body.Crew) }; foreach (DeviceDTO item in body.Devices) { await data.WorkPlansDevices.AddAsync(new WorkPlanDevice { WorkPlan = temp, Device = data.Devices.FirstOrDefault(x => x.Name == item.Name) }); } await data.WorkPlans.AddAsync(temp); await data.SaveChangesAsync(); return(Ok()); } else { return(Unauthorized()); } }
public async Task <IActionResult> SetPriority([FromBody] PriorityDTO body) { foreach (Street item in data.Streets) { if (item.Name == body.Street) { item.Priority = body.Priority; data.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; break; } } await data.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Post([FromBody] IncidentDTO body) { // string id = User.Claims.First(x => x.Type == "UserID").Value; //string role = authentification.Users.FirstOrDefault(x => x.Id == id).Role; if (body.Role != "Dispatcher") { return(Unauthorized()); } else { Incident inc = new Incident(); inc.Type = body.Incident.Type; inc.Confirmed = body.Incident.Confirmed; inc.Status = body.Incident.Status; inc.ETA = body.Incident.ETA; inc.ATA = body.Incident.ATA; inc.ETR = body.Incident.ETR; inc.AffectedCustomers = body.Incident.AffectedCustomers; inc.Voltage = body.Incident.Voltage; inc.ScheduledTime = body.Incident.ScheduledTime; inc.Cause = body.Incident.Cause; inc.Subcause = body.Incident.SubCause; inc.ConstructionType = body.Incident.ConstructionType; inc.Material = body.Incident.Material; inc.Crew = data.Crews.FirstOrDefault(x => x.Id == body.Crew); foreach (DeviceDTO device in body.Devices) { await data.IncidentsDevices.AddAsync(new IncidentDevice() { Incident = inc, Device = data.Devices.FirstOrDefault(x => x.Name == device.Name) }); } await data.Incidents.AddAsync(inc); await data.SaveChangesAsync(); return(Ok()); } }
public async Task <bool> SaveAll() { return(await _context.SaveChangesAsync() > 0); }