Example #1
0
        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);
        }
Example #2
0
        public static ConsularApptVM MapToViewModel(this ConsularAppointment self)
        {
            var viewModel = Mapper.Map <ConsularAppointment, ConsularApptVM>(self);

            return(viewModel);
        }
Example #3
0
 internal static ConsularApptVM MtoVm(ConsularAppointment input)
 {
     throw new NotImplementedException();
 }