public async Task AddItemToAppointmentAsync(AddItemViewModel model, string userName) { var user = await _userHelper.GetUserByEmailAsync(userName); if (user == null) { return; } var vehicle = await _context.Vehicles.FindAsync(model.VehicleId); if (vehicle == null) { return; } var appointmentDetailTemp = await _context.AppointmentDetailsTemp .Where(adt => adt.User == user && adt.Vehicle == vehicle) .FirstOrDefaultAsync(); if (appointmentDetailTemp == null) { appointmentDetailTemp = new AppointmentDetailTemp { LicencePlate = vehicle.VehiclePlateNumber, Vehicle = vehicle, User = user }; _context.AppointmentDetailsTemp.Add(appointmentDetailTemp); } else { _context.AppointmentDetailsTemp.Update(appointmentDetailTemp); } await _context.SaveChangesAsync(); }
public async Task AddItemToPacientAsync(AddItemViewModel model, string userName) { var user = await this.userHelper.GetUserByEmailAsync(userName); if (user == null) { return; } var pacient = await this.context.Pacients.FindAsync(model.PacientId); if (pacient == null) { return; } var orderDetailTemp = await this.context.AppointmentDetailTemps .Where(odt => odt.User == user && odt.Pacient == pacient) .FirstOrDefaultAsync(); if (orderDetailTemp == null) { orderDetailTemp = new AppointmentDetailTemp { Pacient = pacient, User = user, }; this.context.AppointmentDetailTemps.Add(orderDetailTemp); } else { // Cuando un usuario ya pidió una cita para el mismo paciente } await this.context.SaveChangesAsync(); }