/* * static EmbassyAppDb() * { * ConnectionStringSettings connStrSettings = ConfigurationManager.ConnectionStrings["DefaultConnection"]; * if (connStrSettings == null || string.IsNullOrEmpty(connStrSettings.ConnectionString)) * throw new Exception("Fatal error: missing connecting string in web.config file"); * var connectionString = connStrSettings.ConnectionString; * } */ public static bool AddConsularAppt(ConsularApptVM dto, int initalQueueNumber) { var appt = dto.MapToModel(); appt.QueueNumber = initalQueueNumber; using (var context = ApplicationDbContext.Create()) { context.ConsularAppointments.Add(appt); context.SaveChanges(); dto.Id = appt.Id; dto.ActivationCode = appt.ActivationCode; dto.QueueNumber = appt.QueueNumber; } return(true); }
public static ConsularApptVM ConfirmConsularAppt(int appointmentId, string activationCode, ref DateTime?confirmedApptDate, ref int?confirmedQueNumber) { confirmedApptDate = null; confirmedQueNumber = null; ConsularApptVM dto = null; using (var context = ApplicationDbContext.Create()) { ConsularAppointment appt = null; var query = context.ConsularAppointments; appt = query.Where(n => n.Id == appointmentId && n.ActivationCode == activationCode) .DefaultIfEmpty(appt).First(); if (appt != null && appt.AppointmentStatus != 1) // only if it exists in initial or canceled state { using (var transaction = context.Database.BeginTransaction()) { try { appt.QueueNumber = query.Where(n => n.AppointmentDate == appt.AppointmentDate).Max(m => m.QueueNumber); appt.QueueNumber++; appt.AppointmentStatus = 1; context.SaveChanges(); transaction.Commit(); confirmedQueNumber = appt.QueueNumber; dto = appt.MapToViewModel(); } catch (Exception) { transaction.Rollback(); } } } } return(dto); }
public static ConsularAppointment MapToModel(this ConsularApptVM self) { var model = Mapper.Map <ConsularApptVM, ConsularAppointment>(self); return(model); }