public async Task<IHttpActionResult> PostAppointment(AppointmentPostModel model) { string id = db.Users .Where(u => u.UserName == User.Identity.Name) .Select(u => u.Id) .First(); Appointment appointment = new Appointment() { UserId = id, EmployeeId = model.EmployeeId, ServiceId = model.ServiceId, BranchId = model.BranchId, CreatedOn = DateTime.Now, Schedule = new DateTime( model.DateYear, model.DateMonth, model.DateDay, model.DateHour, model.DateMinute, 0) }; var service = db.Services .Where(s => s.Id == model.ServiceId) .FirstOrDefault(); Log newAppointment = db.Logs.Create(); newAppointment.Level = LogLevel.Appointment; newAppointment.Description = "user " + id + " created an appointment."; db.Logs.Add(newAppointment); //PendingPayment pp = db.PendingPayments.Create(); //pp.IsPaid = false; //pp.Value = service.Price; //pp.BranchId = model.BranchId; //db.PendingPayments.Add(pp); db.Appointments.Add(appointment); await db.SaveChangesAsync(); AppointmentNotification notification = db.AppointmentNotifications.Create(); notification.AppointmentId = appointment.Id; notification.BranchId = model.BranchId; notification.EmployeeId = model.EmployeeId; notification.Content = ""; notification.IsRead = false; notification.CreatedOn = DateTime.Now; db.AppointmentNotifications.Add(notification); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = appointment.Id }, appointment); }
public async Task<IHttpActionResult> PutAppointment(int id, Appointment appointment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != appointment.Id) { return BadRequest(); } db.Entry(appointment).State = System.Data.Entity.EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppointmentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }