public ActionResult CreateAppointment(AppointmentViewModel vm)
 {
     using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
     {
         var app = vm.ToEntity();
         if (vm.IsCompany == true)
         {
             app.IsCompany   = true;
             app.CompanyName = vm.CompanyName;
         }
         app.Type = "Khám sức khỏe tổng quát";
         _contactService.AddAppointment(app);
         try
         {
             unitOfWork.Commit();
             return(Json(new
             {
                 Result = true,
                 Message = "Cảm ơn bạn đã đăng ký!",
             }, JsonRequestBehavior.AllowGet));
         }
         catch (Exception ex)
         {
             unitOfWork.Rollback();
             LoggingService.Error(ex);
             return(Json(new
             {
                 Result = false,
                 Message = "Vui lòng kiểm tra lại thông tin",
             }, JsonRequestBehavior.AllowGet));
         }
     }
 }
示例#2
0
        /// <summary>
        /// The create appointment.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="adminUow"></param>
        /// <returns>
        /// The <see cref="AppointmentViewModel"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private AppointmentViewModel CreateAppointment(AppointmentViewModel model, IAdminUnitOfWork adminUow)
        {
            if (model.StartDate.Kind == DateTimeKind.Utc || model.EndDate.Kind == DateTimeKind.Utc)
            {
                throw new Exception("Date time is in UTC Format. Use only LOCACL time for this call");
            }

            var apptStartDateTimeUTC = model.StartDate.Add(model.StartTime.Value).ToUniversalTime();
            var apptEndDateTimeUTC   = model.EndDate.Add(model.EndTime.Value).ToUniversalTime();

            var appt = model.ToEntity();

            appt.StartDate   = apptStartDateTimeUTC;
            appt.EndDate     = apptEndDateTimeUTC;
            appt.StartTime   = new TimeSpan(apptStartDateTimeUTC.Hour, apptStartDateTimeUTC.Minute, 0);
            appt.EndTime     = new TimeSpan(apptEndDateTimeUTC.Hour, apptEndDateTimeUTC.Minute, 0);
            appt.VisitStepId = model.StepSequenceId;
            appt.CreatedBy   = Thread.CurrentPrincipal.Identity.Name;
            appt.IsActive    = true;
            appt.Status      = (int)AppointmentStatusType.Scheduled;

            if (CanCreateAppointment(model))
            {
                // TODO: Move to Monday should be in Settings as Days to adjust for weekends.
                if (appt.StartDate.DayOfWeek == DayOfWeek.Saturday)
                {
                    appt.StartDate = appt.StartDate.AddDays(2);                     // move to Monday.
                    appt.EndDate   = appt.EndDate.AddDays(2);
                }
                else if (appt.StartDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    appt.StartDate = model.StartDate.AddDays(1);                     // move to Monday.
                    appt.EndDate   = model.EndDate.AddDays(1);
                }

                _logger.Debug(
                    "CAN Create Visit:{0} start:{1}:{3} end:{2}:{4}",
                    appt.VisitId,
                    appt.StartDate,
                    appt.EndDate,
                    appt.StartTime,
                    appt.EndTime);

                adminUow.AppointmentRepository.Insert(appt);

                if (model.IsTermination)
                {
                    TerminateAllFutureVisits(model);
                }
            }

            var viewModel = new AppointmentViewModel
            {
                Id            = appt.Id,
                SubjectId     = appt.SubjectId,
                AppUserId     = appt.AppUserId,
                CalendarStart = apptStartDateTimeUTC.ToLocalTime().ToString(CultureInfo.InvariantCulture),
                CalendarEnd   = apptEndDateTimeUTC.ToLocalTime().ToString(CultureInfo.InvariantCulture),
                Title         = appt.Title,
                Description   = appt.Description
            };


            return(viewModel);
        }