Example #1
0
        public async Task <IActionResult> MakeAnAppointment(AppointmentInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("MakeAnAppointment", new { input.SalonId, input.ServiceId }));
            }

            DateTime dateTime;

            try
            {
                dateTime = this.dateTimeParserService.ConvertStrings(input.Date, input.Time);
            }
            catch (System.Exception)
            {
                return(this.RedirectToAction("MakeAnAppointment", new { input.SalonId, input.ServiceId }));
            }

            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            var userId = await this.userManager.GetUserIdAsync(user);

            await this.appointmentsService.AddAsync(userId, input.SalonId, input.ServiceId, dateTime);

            return(this.RedirectToAction("Index"));
        }
Example #2
0
        public void AddReturnCorrectly(int procedureId, string oldPolish, int time)
        {
            var procedures = new List <Procedure>
            {
                new Procedure
                {
                    Id = 1
                },
                new Procedure
                {
                    Id = 2
                }
            };

            this.db.Procedures.AddRange(procedures);
            this.db.SaveChanges();

            var model = new AppointmentInputModel
            {
                ProcedureId = procedureId,
                OldPolish   = oldPolish,
                Date        = DateTime.Today.ToString(),
                Hour        = TimeSpan.FromHours(time),
                isTest      = true
            };

            var userId = "1";

            var isValid = this.appointmentService.Add(model, userId);

            Assert.True(isValid);
        }
        public ActionResult Create()
        {
            var inputAppointmentModel = new AppointmentInputModel();
            var doctors = doctorsService.GetAll();
            var outputDoctors = this.Mapper.Map<IEnumerable<DoctorBasicViewModel>>(doctors);

            inputAppointmentModel.Doctors = outputDoctors;

            return this.View(inputAppointmentModel);
        }
        public IActionResult Add()
        {
            var model = new AppointmentInputModel
            {
                Procedures    = this.procedureService.GetProceduresDropDownList(),
                DisabledDates = this.appointmentService.GetDisabledDates()
            };

            return(View(model));
        }
        public ActionResult Create()
        {
            var inputAppointmentModel = new AppointmentInputModel();
            var doctors       = doctorsService.GetAll();
            var outputDoctors = this.Mapper.Map <IEnumerable <DoctorBasicViewModel> >(doctors);

            inputAppointmentModel.Doctors = outputDoctors;

            return(this.View(inputAppointmentModel));
        }
        public ActionResult <AppointmentViewModel> Post(AppointmentInputModel appointmentInputModel)
        {
            var response = _Service.Save(appointmentInputModel.PatientId, appointmentInputModel.Date);

            if (response.Error == false)
            {
                return(Ok(response.Object));
            }
            else
            {
                return(BadRequest(response.Message));
            }
        }
        public ActionResult Create(AppointmentInputModel appointment)
        {
            if (this.ModelState.IsValid)
            {
                var appointmentDb = this.Mapper.Map <Appointment>(appointment);
                appointmentDb.CreatedOn = DateTime.Now;
                appointmentDb.PatientId = this.User.Identity.GetUserId();
                //this.appointmentsService.Add(appointmentDb);
                this.TempData["AppointmentAddedMsg"] = "Succesfully appointment added";
                return(this.Redirect("/"));
            }

            return(View(appointment));
        }
        public ActionResult Create(AppointmentInputModel appointment)
        {
            if (this.ModelState.IsValid)
            {
                var appointmentDb = this.Mapper.Map<Appointment>(appointment);
                appointmentDb.CreatedOn = DateTime.Now;
                appointmentDb.PatientId = this.User.Identity.GetUserId();
                //this.appointmentsService.Add(appointmentDb);
                this.TempData["AppointmentAddedMsg"] = "Succesfully appointment added";
                return this.Redirect("/");
            }

            return View(appointment);

        }
        public async Task <IActionResult> Save([FromForm] AppointmentInputModel inputModel)
        {
            // Create model for service
            var serviceModel = AutoMapperConfig.MapperInstance.Map <AppointmentServiceModel>(inputModel);

            // Validate
            var appointmentSlotIsOccupied = await this.appointmentService
                                            .GetAllByDate(serviceModel.Start)
                                            .Where(a => a.Start.Hour == serviceModel.Start.Hour)
                                            .FirstOrDefaultAsync();

            if (appointmentSlotIsOccupied != null)
            {
                return(this.BadRequest());
            }

            // Set up model for service
            var user = await this.userManager.GetUserAsync(this.User);

            serviceModel.UserId = user.Id;

            // Create appointment in server
            var appointmentId = await this.appointmentService.Create(serviceModel);

            // Enter user phone number, if provided
            if (!string.IsNullOrEmpty(serviceModel.PhoneNumber) && (await this.userManager.GetPhoneNumberAsync(user)) == null)
            {
                await this.userManager.SetPhoneNumberAsync(user, serviceModel.PhoneNumber);
            }

            var scheme  = this.HttpContext.Request.Scheme;
            var baseUrl = this.HttpContext.Request.Host.Value;

            //TODO: Translate messages into Bulgarian
            var urlElement     = $"<a href=\"{scheme}://{baseUrl}/home/appointment\"><h3>Appointment Details and Approval</h3></a>";
            var adminEmailText = $"<div>Hello, </div> <div></div> <div>You have a new appointment. Have a look below:</div><div></div><div>{urlElement}</div><div></div><div>Thank you!</div>";
            var userEmailText  = $"<div>Hello, </div> <div></div> <div>{AppointmentAwaitingApprovalText}</div><div>Thank you!</div>";

            var adminEmail = (await this.userManager.GetUsersInRoleAsync(GlobalConstants.AdministratorRoleName)).FirstOrDefault().Email;

            // Send emails to admin and user
            await this.emailSender.SendEmailAsync(user.Email, user.UserName, adminEmail, this.GetEmailSubject(serviceModel.Start), adminEmailText);

            await this.emailSender.SendEmailAsync(adminEmail, GlobalConstants.SystemName, user.Email, this.GetEmailSubject(serviceModel.Start), userEmailText);

            return(this.Ok());
        }
Example #10
0
        public async Task <IActionResult> MakeAnAppointment(string partnerId, int serviceId)
        {
            var partnerService = await this.partnerServicesService.GetByIdAsync <PartnerServiceSimpleViewModel>(partnerId, serviceId);

            if (partnerService == null || !partnerService.Available)
            {
                return(this.View("UnavailableService"));
            }

            var viewModel = new AppointmentInputModel
            {
                PartnerId = partnerId,
                ServiceId = serviceId,
            };

            return(this.View(viewModel));
        }
Example #11
0
        public async Task <IActionResult> MakeAnAppointment(string salonId, int serviceId)
        {
            var salonService = await this.salonServicesService.GetByIdAsync <SalonServiceSimpleViewModel>(salonId, serviceId);

            if (salonService == null || !salonService.Available)
            {
                return(this.View("UnavailableService"));
            }

            var viewModel = new AppointmentInputModel
            {
                SalonId   = salonId,
                ServiceId = serviceId,
            };

            return(this.View(viewModel));
        }
Example #12
0
        public void AddReturnInvalid(int procedureId, string oldPolish, int time)
        {
            var procedures = new List <Procedure>
            {
                new Procedure
                {
                    Id = 1
                },
                new Procedure
                {
                    Id = 2
                }
            };

            var appointment = new Appointment
            {
                Id   = 1,
                Date = new DateTime(2020, 4, 27),
                Hour = TimeSpan.FromHours(11)
            };

            this.db.Procedures.AddRange(procedures);
            this.db.Appointments.Add(appointment);
            this.db.SaveChanges();

            var model = new AppointmentInputModel
            {
                ProcedureId = procedureId,
                OldPolish   = oldPolish,
                Date        = new DateTime(2020, 4, 27).ToString(),
                Hour        = TimeSpan.FromHours(time),
                isTest      = true
            };

            var userId = "1";

            var isValid = this.appointmentService.Add(model, userId);

            Assert.False(isValid);
        }
Example #13
0
        public async Task <IActionResult> CreateOffering(AppointmentInputModel appointmentInputModel)
        {
            var user = await _userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                ViewBag.ErrorMessage = "Appointment start should be after at least one hour but not later than in 1 year. Appointment duration should be between 15 minutes and 8 hours. Please input a valid start and end.";
                return(View("CreateOffering"));
            }

            var duration = (appointmentInputModel.TimeEnd).Subtract(appointmentInputModel.TimeStart).TotalMinutes;

            if (duration < 15 || duration > 8 * 60)
            {
                ViewBag.ErrorMessage = "Appointments should last between 15 minutes and 8 hours. Please input a valid start and end.";
                return(View("CreateOffering"));
            }

            var minutesFromNow = (int)(appointmentInputModel.TimeEnd).Subtract(DateTime.Now).TotalMinutes;

            if (minutesFromNow < 60 || minutesFromNow > 365 * 24 * 80)
            {
                ViewBag.ErrorMessage = "Appointment start should be after at least one hour but not later than in 1 year. Please input a valid start and end.";
                return(View("CreateOffering"));
            }

            if (this._appointmentService.DuplicateOfferingExists(user, appointmentInputModel.TimeStart, appointmentInputModel.TimeEnd))
            {
                ViewBag.ErrorMessage = "Your new offering's time overlaps with an existing offering. Please input a valid start and end or cancel your other offering before you proceed to create the new one.";
                return(View("CreateOffering"));
            }

            await this._appointmentService
            .CreateAppointment(user, appointmentInputModel.TimeStart, appointmentInputModel.TimeEnd);


            return(RedirectToAction("Index"));
        }
        public IActionResult CreateAppointment(AppointmentInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            if (model.AppointmentDate < DateTime.UtcNow)
            {
                return(this.View(model));
            }
            if (model.AppointmentDate > DateTime.UtcNow.AddDays(10))
            {
                return(this.View(model));
            }

            var username      = this.User.Identity.Name;
            var ad            = adService.GetAd(model.AdId);
            var userProfile   = profileService.GetUserByUsername(username);
            var agencyProfile = profileService.GetAgencyById(ad.AgencyProfileId);

            appointmentService.Create(ad, userProfile, agencyProfile, model.AppointmentDate);

            return(this.Redirect(GlobalConstants.homeUrl));
        }
Example #15
0
        public async Task <IActionResult> MakeAnAppointment(AppointmentInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("MakeAnAppointment", new { input.PartnerId, input.ServiceId }));
            }

            DateTime dateTime;

            try
            {
                dateTime = this.dateTimeParserService.ConvertStrings(input.Date, input.Time);
            }
            catch (System.Exception)
            {
                return(this.RedirectToAction("MakeAnAppointment", new { input.PartnerId, input.ServiceId }));
            }

            var user = await this.userManager.GetUserAsync(this.HttpContext.User);

            var userId = await this.userManager.GetUserIdAsync(user);

            await this.appointmentsService.AddAsync(userId, input.PartnerId, input.ServiceId, dateTime, input.AddressStart, input.AddressEnd, input.Comment, input.Price);

            var callbackUrl = this.Url.Page("/Appoinments");

            // Send Email
            var uemail = user?.Email;

            await this.emailSender.SendEmailAsync(
                uemail,
                "Cita Agendada",
                $"Haz agendado una cita exitosamente para el día {dateTime}, puedes ver los demás detalles haciendo <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>click aquí</a>.");

            return(this.RedirectToAction("Index"));
        }
        public IActionResult Add(AppointmentInputModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Procedures         = this.procedureService.GetProceduresDropDownList();
                model.DisabledDates      = this.appointmentService.GetDisabledDates();
                this.ViewData["invalid"] = ErrorMessages.AppointmentInvalidAdd;
                return(View(model));
            }

            var userId  = this.userManager.GetUserId(this.User);
            var isValid = this.appointmentService.Add(model, userId);

            if (!isValid)
            {
                this.ViewData["error"] = string.Format(ErrorMessages.AppointmentBusy, model.Hour);
                model.Procedures       = this.procedureService.GetProceduresDropDownList();
                return(View(model));
            }
            this.TempData["successfully"] = string.Format(
                SuccessfullyMessages.AppointmentSuccessfullyAdd, model.Date, model.Hour);

            return(RedirectToAction("Index", "Home"));
        }
Example #17
0
        public bool Add(AppointmentInputModel model, string userId)
        {
            DateTime currentDate;

            try
            {
                currentDate = DateTime.Parse(model.Date);
            }
            catch (Exception e)
            {
                throw new InvalidCastException(
                          string.Format(ExceptionMessages.InvalidCastDate, model.Date, e));
            }

            var ReCaptcha = this.reCAPTCHAService.Verify(model.Token);

            if (!model.isTest && !ReCaptcha.Result.Success && ReCaptcha.Result.Score <= 0.5)
            {
                return(false);
            }

            var isExistHour = this.db.Appointments
                              .Where(x => x.Date == currentDate)
                              .Any(x => x.Hour == model.Hour);

            var procedureDuration = this.db.Procedures
                                    .Where(x => x.Id == model.ProcedureId)
                                    .Select(x => x.Duration)
                                    .FirstOrDefault();

            var previous = this.db.Appointments
                           .OrderByDescending(x => x.Hour)
                           .Where(x => x.Date == currentDate && x.Hour < model.Hour)
                           .Select(x => x.Hour)
                           .FirstOrDefault();

            var next = this.db.Appointments
                       .OrderBy(x => x.Hour)
                       .Where(x => x.Date == currentDate && x.Hour > model.Hour)
                       .Select(x => x.Hour)
                       .FirstOrDefault();

            if (isExistHour || model.Hour + procedureDuration > next && next > TimeSpan.Zero)
            {
                return(false);
            }

            if (!this.db.Procedures.Any(x => x.Id == model.ProcedureId) ||
                model.OldPolish != "Да" &&
                model.OldPolish != "Не" ||
                model.Hour < TimeSpan.FromHours(9) ||
                model.Hour > TimeSpan.FromHours(18))
            {
                return(false);
            }

            var appointment = new Appointment
            {
                NailPolish  = model.OldPolish,
                Date        = currentDate,
                Hour        = model.Hour,
                UserId      = userId,
                ProcedureId = model.ProcedureId
            };

            this.db.Appointments.Add(appointment);
            this.db.SaveChanges();
            return(true);
        }