Beispiel #1
0
        public ActionResult CreateAppointmentAction(CreateAppointmentModel Model)
        {
            if (ModelState.IsValid)
            {
                string AppDate = Model.Hour + ":00-" + (Int32.Parse(Model.Hour) + 1).ToString() + ":00 - " + Model.Date;

                if (_db.Appointments.Any(App => App.FK_Doctor.ToString().Equals(Model.Doctor.ToString()) && App.Date.Equals(AppDate)))
                {
                    TempData["danger"] = "Please select other date or doctor.";
                    return(RedirectToAction("View", "Service", new { id = Model.Id }));
                }

                Guid AppId = Guid.NewGuid();

                _db.Appointments.Add(new Appointment
                {
                    Id                = AppId,
                    FK_Doctor         = Guid.Parse(Model.Doctor),
                    FK_User_Appointed = Guid.Parse(User.Identity.Name),
                    Date              = AppDate,
                    IsConfirmed       = false
                });

                _db.SaveChanges();

                _db.Appointments_Service.Add(new Appointments_Service
                {
                    Id             = Guid.NewGuid(),
                    FK_Appointment = AppId,
                    FK_Service     = Model.Id
                });

                _db.SaveChanges();

                TempData["success"] = "Your appoiment has been created.";
                return(RedirectToAction("View", "Service", new { id = Model.Id }));
            }

            TempData["danger"] = "Unexpected error please try again.";
            return(RedirectToAction("View", "Service", new { id = Model.Id }));
        }
Beispiel #2
0
 public ActionResult CreateAppointment(CreateAppointmentModel model)
 {
     // make sure you set the culture info in the web.config!
     using (var appMgr = ServiceLocator.Resolve <IAppointmentManager>())
     {
         using (var docMgr = ServiceLocator.Resolve <IDoctorManager>())
         {
             model.Doctors = docMgr.Doctors;
             if (ModelState.IsValid)
             {
                 Appointment a = new Appointment();
                 a.Date     = model.Date;
                 a.DoctorId = model.DoctorId;
                 a.Reason   = model.Reason;
                 a.Patient  = User.Identity.Name;
                 appMgr.Create(a);
                 return(View("AppointmentCreated", model));
             }
             // If we got this far, something failed, redisplay form
             ModelState.AddModelError("", "There are some problems with your input.");
             return(View(model));
         }
     }
 }
        public Task <Result <object> > Add(CreateAppointmentModel model)
        => Result <object> .TryAsync(async() =>
        {
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);

            if (model.UserId == Guid.Empty)
            {
                model.UserId = generalDataService.User.Id;
            }
            var user = (await _membershipServiceApi.SystemUserApiService.Get(
                            new MembershipService.ApiClient.Models.BaseModel {
                Id = model.UserId
            })).Data;
            if (user == null)
            {
                return(Result <object> .Failed(Error.WithData(1000, new[] { "User not found" })));
            }

            var validateAppointment = await _appointmentExceptionBiz.ValidateAppointment(model.Date);
            if (validateAppointment.Success && validateAppointment.Data)
            {
                return(Result <object> .Failed(Error.WithData(1000,
                                                              new[] { "Sorry , there are no available representative in the requested time" })));
            }

            var duplicateTime =
                await _repository.FirstOrDefaultAsNoTrackingAsync <Appointment>(a => a.Date == model.Date);
            if (duplicateTime.Success && duplicateTime.Data != null)
            {
                return(Result <object> .Failed(Error.WithData(1000,
                                                              new[] { "Sorry , there are no available representative in the requested time" })));
            }

            Guid?invoiceId = null;
            if (model.Duration > 20)
            {
                invoiceId = (await _invoiceBiz.Add(new CreateInvoiceModel
                {
                    Amount = 200,
                    Description = @"1xVIP appointment $200 
Sub total = $200
Taxes = $10
Total = $210",
                    Status = InvoiceStatus.Pending,
                    Title = "VIP Appointment",
                    Enabled = true,
                    UserId = model.UserId
                })).Data;
            }

            var appointment = new Appointment
            {
                Id               = Guid.NewGuid(),
                InvoiceId        = invoiceId,
                Description      = model.Description,
                CreationDate     = DateTime.Now,
                Date             = model.Date,
                Duration         = model.Duration,
                Type             = model.Type,
                UserId           = !isAdmin ? generalDataService.User.Id : user.Id,
                RepresentativeId = isAdmin ? generalDataService.User.Id : Guid.Empty,
                Title            = model.Title,
                Approved         = true
            };

            _repository.Add(appointment);

            var usersurvey = await _repository.ListAsync <UserSurvey>(us => us.UserId == generalDataService.User.Id);
            if (usersurvey.Success && usersurvey.Data != null && usersurvey.Data.Any())
            {
                var userSurveyIds = usersurvey.Data.Select(us => us.Id).ToList();
                var taxes         = await _repository.ListAsync <Tax>(t =>
                                                                      t.UserSurveyId != null && userSurveyIds.Contains(t.UserSurveyId.Value) &&
                                                                      t.Status == (int)TaxStatus.SetConsultation);

                if (taxes.Success && taxes.Data != null && taxes.Data.Any())
                {
                    taxes.Data.ToList().ForEach(t => t.Status = (byte)TaxStatus.PendingConsultation);
                }
            }

            await _repository.CommitAsync();


            if (appointment.InvoiceId == null)
            {
                _coreSmtpClient.SendComplimentryConsultation(user.Email,
                                                             user.Firstname + " " + user.Lastname, appointment.Date.ToString("F"));


                await _messageBiz.Add(new CreateMessageModel
                {
                    Title = "Your Appointment",
                    Body  =
                        $"Your appointment has been confirmed. One of our AccNet representatives will reach out to you at the scheduled time : {appointment.Date.ToString("F")} (PACIFIC STANDARD TIME)",
                    ToUser   = user.Id,
                    Priority = MessagePriority.High
                });

                _coreSmtpClient.SendAppointmentBookNotif("*****@*****.**",
                                                         user.Firstname + " " + user.Lastname,
                                                         appointment.Date.ToString("F"));
            }

            return(Result <object> .Successful(new
            {
                message = invoiceId.HasValue
                        ? $"To confirm your VIP consultation on {appointment.Date.ToString("F")} (PACIFIC STANDARD TIME), please click OK to kindly pay the fee for this call. Once paid you will receive a confirmation email detailing the selected date and time. Thank you"
                        : $"Your appointment has been confirmed. One of our AccNet representatives will reach out to you at the scheduled time : {appointment.Date.ToString("F")} (PACIFIC STANDARD TIME)",
                vip = invoiceId.HasValue
            }));
        });
Beispiel #4
0
 public Task <Result <object> > Add(CreateAppointmentModel model)
 => _AppointmentBiz.Add(model);