public FullCalendarVo(Appointment appointment, long timezoneOffset) { id = appointment.AppointmentId; title = "Viewing for " + appointment.Property.FullStreetAddress; allDay = false; start = appointment.AppointmentDateTime.Value.AddMinutes(timezoneOffset); description = appointment.Text; address = appointment.Property.FullStreetAddress; }
public string CreateAppointment(long listingKey, DateTime? appointmentDate, string notes) { try { User user = this.GetUserFromCookie(); if (user == null) { Trace.WriteLine("[WARN] User appointments requested but not logged in."); return null; } Appointment temp = new Appointment { ListingKey = listingKey, AppointmentDateTime = appointmentDate, Text = notes }; Appointment appointment = _appointmentManager.AddAppointment(temp, user.UserId); AppointmentCreateResponse aResponse = new AppointmentCreateResponse { ResponseCode = 200, Message = "Appointment successfully created." }; return JsonConvert.SerializeObject(aResponse); } catch (BaseException e) { AppointmentCreateResponse aResponse = new AppointmentCreateResponse { ResponseCode = 400, Message = e.Message, }; return JsonConvert.SerializeObject(aResponse); } catch (Exception e) { AppointmentCreateResponse aResponse = new AppointmentCreateResponse { ResponseCode = 500, Message = "Sorry we could not handle your request at the moment. Please try later.\n[ Technical detail: " + e.Message + " ]" }; return JsonConvert.SerializeObject(aResponse); } }
public HttpResponseMessage AddUserAppointment(Appointment appointment) { try { Appointment updatedAppointment = _appointmentManager.AddAppointment(appointment, this.User.User.UserId); return Request.CreateResponse(HttpStatusCode.OK, updatedAppointment); } catch (ParamMissingException e){ return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse{ Message = e.Message }); } catch (AlreadyExistsException e){ return Request.CreateResponse(HttpStatusCode.Conflict, new ErrorResponse{ Message = e.Message }); }catch (InvalidValueException e){ return Request.CreateResponse(HttpStatusCode.NotAcceptable, new ErrorResponse{ Message = e.Message }); }catch (UserNotFoundException e){ return Request.CreateResponse(HttpStatusCode.NotFound, new ErrorResponse{ Message = e.Message }); }catch (Exception e){ return Request.CreateResponse(HttpStatusCode.InternalServerError, new ErrorResponse { Message = "Oops, server encountered an issue... " + e.Message }); } }
public Appointment AddAppointment(Appointment appointment, string userId) { if (string.IsNullOrWhiteSpace(userId)) throw new ParamMissingException("Missing user ID."); if (appointment == null) throw new ParamMissingException("You must provide appointment details."); /* * We no longer know the agent at booking time. Req. change. if (string.IsNullOrWhiteSpace(appointment.AgentId)) throw new ParamMissingException("You must specify an agent ID."); */ if (appointment.AppointmentDateTime == null || appointment.AppointmentDateTime < DateTime.UtcNow //temp comment out on Asad's request. ) throw new InvalidValueException("Appointment date and time are missing or in past."); if (string.IsNullOrWhiteSpace(appointment.Text)) appointment.Text = null; // Get all not viewed appointments of this user and see if anything overlaps its time. DateTime newAppStartDate = appointment.AppointmentDateTime.Value; DateTime newAppEndDate = newAppStartDate.AddMinutes(30); List<Appointment> overlappingAppointments = Repository.Query<Appointment>(oldAppointment => //dateToCheck >= startDate && dateToCheck < endDate newAppStartDate >= oldAppointment.AppointmentDateTime && newAppStartDate <= DbFunctions.AddMinutes(oldAppointment.AppointmentDateTime.Value, 30) && oldAppointment.Deleted != true && oldAppointment.Status.Equals("Shown") == false).ToList(); if(overlappingAppointments == null || overlappingAppointments.Count <= 0) overlappingAppointments = Repository.Query<Appointment>(x => newAppEndDate >= x.AppointmentDateTime.Value && newAppEndDate <= DbFunctions.AddMinutes(x.AppointmentDateTime.Value, 30) && x.Deleted != true && x.Status.Equals("Shown") == false ).ToList(); if (overlappingAppointments != null && overlappingAppointments.Count > 0) throw new AlreadyExistsException("Selected time clashes with another appointment."); Property property = Repository.Single<Property>( x => x.ListingKey == appointment.ListingKey); if (property == null) throw new InvalidValueException("No property with specfied ID provided."); User user = Repository.Single<User>(x => x.UserId.Equals(userId) && x.Deleted != true, "Credential"); if (user == null) throw new InvalidValueException("Creating user not found."); appointment.UserId = userId; appointment.AgentId = null; appointment.AgentNotes = null; appointment.Status = null; Repository.Add<Appointment>(appointment); // Check if user has its ZenIdSet if (string.IsNullOrWhiteSpace(user.ZenmateId)) { // get this user's ID long? userZendeskId = Services.Ticketing.GetUserId(user.Credential.Email); if(userZendeskId == null) userZendeskId = Services.Ticketing.RegisterEndUser(user, user.Credential.Email); if (userZendeskId == null) throw new InvalidValueException("Could not setup appointment, please contact us on our chat."); user.ZenmateId = string.Format("{0}", userZendeskId.Value); } if (user.ZenmateTicketId == null) { // Zendesk API previously provided an int ID. // Recently they updated to a long ID for tickets... // TODO: Change zendesk ticket ID to long rather than int. int? zendeskTicketId = (int?)Services.Ticketing.GetUserTicket(user.Credential.Email); if (zendeskTicketId == null) zendeskTicketId = (int?)Services.Ticketing.CreateUserTicket(long.Parse(user.ZenmateId), user.Credential.Email); if (zendeskTicketId == null) throw new InvalidValueException("Could not find your conversation thread, please contact us on support chat."); user.ZenmateTicketId = zendeskTicketId; } // Ok now it seems we should have the best chance of // successfully adding a comment. Lets save first so we have the correct ID // from DB to create link with. Repository.Save(); TimeZoneInfo pst = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); string commentBody = string.Format( "{0} has requested an appointment for {6}. You can contact them at " + "{1}. Booked property is at {2} of type '{3}'. Their message: {7}. Once it has been shown" + ", please click on this link to mark this appointment " + " as shown {4}{5}", user.DisplayName, user.Credential.Email, property.FullStreetAddress , property.PropertyType, "http://www.reop.com/api/appointments/shown?id=" , appointment.AppointmentId, TimeZoneInfo.ConvertTimeFromUtc(appointment.AppointmentDateTime.Value.ToUniversalTime(), pst).ToString(), appointment.Text == null ? "None" : appointment.Text.Trim()); // Finally add the comment now. Services.Ticketing.AddComment(long.Parse(user.ZenmateId), user.ZenmateTicketId.Value, commentBody); return appointment; }