public async Task <IActionResult> CreateEvent(Event newEvent) { var calendar = await _context.Calendars.FindAsync(newEvent.CalendarID); if (calendar == null) { return(BadRequest("No such Calendar")); } if (newEvent.StartDate > newEvent.EndDate) { return(BadRequest("Event cannot end before it started")); } if (newEvent.EventTypeID == 0 && newEvent.EventType.ID != 0) { newEvent.EventTypeID = newEvent.EventType.ID; } else if (newEvent.EventTypeID == 0 && newEvent.EventType.ID == 0 && newEvent.EventType.Label != "") { await _context.EventTypes.AddAsync(newEvent.EventType); await _context.SaveChangesAsync(); } await _context.Events.AddAsync(newEvent); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> CreateCalendar(Calendar calendar) { var stable = await _context.Stables .FindAsync(calendar.StableID); if (stable == null) { return(BadRequest("No such Stable")); } await _context.Calendars.AddAsync(calendar); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> CreatePerson(PersonDto personDto) { if (personDto.Name == null || personDto.Surname == null) { return(BadRequest()); } var person = new Person { Name = personDto.Name, Surname = personDto.Surname }; await _context.Persons.AddAsync(person); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetPerson), new { id = person.ID }, person)); }
public async Task <IActionResult> CreateMember(MembershipDto memberDto) { if (memberDto.PersonID == null || memberDto.StableID == null) { return(BadRequest()); } var person = new Membership { Person = memberDto.Person, Stable = memberDto.Stable, StableID = (int)memberDto.StableID, }; await _context.Memberships.AddAsync(person); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetMember), new { id = person.PersonID }, person)); }
public async Task <IActionResult> CreateHorse(HorseDto horseDto) { if (horseDto.Name == null || horseDto.OwnerID <= 0) { return(BadRequest()); } var horse = new Horse { Name = horseDto.Name, BoxID = horseDto.BoxID, OwnerID = horseDto.OwnerID }; await _context.Horses.AddAsync(horse); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetHorse), new { id = horse.ID }, horse)); }
public async Task <IActionResult> DeleteItemType(int id) { var stockItem = await _context.StockItems.FindAsync(id); if (stockItem == null) { return(NotFound()); } _context.StockItems.Remove(stockItem); await _context.SaveChangesAsync(); return(Ok()); }