public IHttpActionResult Reserv(ReservModel model) { if (!ModelState.IsValid) { return(BadRequest("Invalid data")); } var quest = questService.GetAll().Where(x => x.Id == model.QuestId).FirstOrDefault(); double cost = quest.Price; if (!String.IsNullOrEmpty(model.Code)) { if (reservationService.VerifyCertificateCode(model.Code)) { cost = 0; } else { return(BadRequest("Invalid code")); } } reservationService.Add(new ReservDTO { Quest = quest, DateTimeSections = model.Date + " " + model.Time, Cost = cost }); return(Ok($"Quest \"{quest.Name}\" reserved for {model.Date} on {model.Time}\nCost: {cost} grn")); }
public Task <Reserv> ReservPlace(ReservModel rm) { _context.reservations.AddAsync(new Reserv { ClientId = rm.ClientId.Value, PlaceId = rm.PlaceId.Value, StartPeriod = rm.StartPeriod.Value.Date, EndPeriod = rm.EndPeriod.Value.Date }); _context.SaveChangesAsync(); return(Task.Run(() => _context.reservations.OrderByDescending(r => r.ReservId).First())); }
public ActionResult <Reserv> AddReserv([FromBody] ReservModel rm) { return(Created("Created reserv", reservationService.ReservPlace(rm).Result)); }