public void AddAppointment()
        {
            var dateTime =
                DateTime.ParseExact(DateOfAppointment.ToShortDateString() + " " + TimeOfAppointment.ToLongTimeString(),
                                    "M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);

            AppointmentDAO.AddAppointment(Cost, dateTime, NatureOfAct, Id);
            MessageBox.Show("Appointment added!");
        }
        public async Task <IActionResult> AppointmentDate(AppointmentDateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.EndOfWork < model.StartOfWork)
            {
                ViewBag.Message = "Дата окончания рабочего дня не может быть меньше начала";
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            var employee = this._unitOfWork.Employees.Find(e => e.UserID == user.Id).FirstOrDefault();
            var doctor   = this._unitOfWork.Doctors.Find(d => d.EmployeeID == employee.EmployeeID).FirstOrDefault();

            if (model.AppointmentDateId == 0)
            {
                var existDate = this._unitOfWork.DatesOfAppointments
                                .Find(d => d.DoctorID == doctor.ID && DateTime.Compare(d.Date, model.Date) == 0)
                                .SingleOrDefault();

                if (existDate == null)
                {
                    DateOfAppointment date = new DateOfAppointment
                    {
                        DoctorID        = doctor.ID,
                        Date            = model.Date,
                        PeriodOfWorking = string.Format("{0}-{1}", model.StartOfWork, model.EndOfWork)
                    };
                    ViewBag.Message = "Дата приема создана";
                    this._unitOfWork.DatesOfAppointments.Add(date);
                }
                else
                {
                    ViewBag.Message = "В этот день уже есть прием";
                }
            }
            else
            {
                DateOfAppointment date = this._unitOfWork.DatesOfAppointments.Get(model.AppointmentDateId);
                date.Date            = model.Date;
                date.PeriodOfWorking = string.Format("{0}-{1}", model.StartOfWork, model.EndOfWork);
                ViewBag.Message      = "Дата приема успешно изменена";
            }

            this._unitOfWork.Save();
            return(View("Info"));
        }
        public async Task <IActionResult> AppointmentDate(int appointmentDateId)
        {
            AppointmentDateViewModel model = new AppointmentDateViewModel();

            ViewBag.Message = "Создание даты приема";
            if (appointmentDateId != 0)
            {
                DateOfAppointment date   = this._unitOfWork.DatesOfAppointments.Get(appointmentDateId);
                string[]          values = date.PeriodOfWorking.Split('-');
                model = new AppointmentDateViewModel
                {
                    AppointmentDateId = date.DateOfAppointmentID,
                    DoctorId          = date.DoctorID,
                    Date            = date.Date.Date,
                    PeriodOfWorking = date.PeriodOfWorking,
                    StartOfWork     = int.Parse(values[0]),
                    EndOfWork       = int.Parse(values[1])
                };
                ViewBag.Message = "Изменение даты приема";
            }
            return(View(model));
        }
Exemple #4
0
        public async Task <IActionResult> Records()
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                if (User.IsInRole(UserRole.Пациент.ToString()))
                {
                    var recordsTime = this._unitOfWork.ReservedTimes
                                      .Find(r => r.UserID == user.Id && DateTime.Compare(r.Time, DateTime.Now) >= 1);
                    List <RecordViewModel> models = new List <RecordViewModel>();
                    foreach (var time in recordsTime)
                    {
                        DateOfAppointment recordDate  = this._unitOfWork.DatesOfAppointments.Get(time.DateOfAppointmentID);
                        Doctor            doctor      = this._unitOfWork.Doctors.Get(recordDate.DoctorID);
                        Employee          employee    = this._unitOfWork.Employees.Get(doctor.EmployeeID);
                        ApplicationUser   doctorsUser = this._unitOfWork.Users.Get(employee.UserID);
                        Service           service     = this._unitOfWork.Services.Get(time.ServiceID);

                        models.Add(new RecordViewModel
                        {
                            ApplicationUser = doctorsUser,
                            Doctor          = doctor,
                            Date            = time.Time,
                            Service         = service,
                            ReservedTime    = time
                        });
                    }

                    return(View(models));
                }
            }

            ViewBag.Message = "Произошли некоторые ошибки";
            return(View("Info"));
        }
Exemple #5
0
        public async static Task Initialize(MedicCroporateContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            context.Database.EnsureCreated();

            if (context.Users.Any())
            {
                return;
            }

            string[]       roleNames = { "Администратор", "Пациент", "Врач", "Бухгалтер", "Ресепшен" };
            IdentityResult roleResult;

            foreach (var roleName in roleNames)
            {
                var roleExist = await roleManager.RoleExistsAsync(roleName);

                if (!roleExist)
                {
                    roleResult = await roleManager.CreateAsync(new ApplicationRole(roleName));
                }
            }

            var powerUser = new ApplicationUser
            {
                UserName  = "******",
                Password  = "******",
                Email     = "*****@*****.**",
                Gender    = Gender.Мужской,
                LastName  = "Admin",
                FirstName = "Admin"
            };

            var userPatient = new ApplicationUser
            {
                UserName  = "******",
                Password  = "******",
                Email     = "*****@*****.**",
                Gender    = Gender.Мужской,
                LastName  = "Patient",
                FirstName = "Patient",
                Role      = UserRole.Пациент
            };

            var userDoctor = new ApplicationUser
            {
                UserName  = "******",
                Password  = "******",
                Email     = "*****@*****.**",
                Gender    = Gender.Мужской,
                LastName  = "Doctor",
                FirstName = "Doctor",
                Role      = UserRole.Врач
            };

            var userCalculator = new ApplicationUser
            {
                UserName  = "******",
                Password  = "******",
                Email     = "*****@*****.**",
                Gender    = Gender.Мужской,
                LastName  = "Calcuc",
                FirstName = "Calcuc",
                Role      = UserRole.Бухгалтер
            };


            var _user = await userManager.FindByEmailAsync(powerUser.Email);

            if (_user == null)
            {
                var createPowerUser = await userManager.CreateAsync(powerUser, powerUser.Password);

                if (createPowerUser.Succeeded)
                {
                    var user = await userManager.FindByNameAsync(powerUser.UserName);

                    var employee = new Employee
                    {
                        UserID          = user.Id,
                        ApplicationUser = user
                    };

                    await context.Employees.AddAsync(employee);

                    await userManager.AddToRoleAsync(powerUser, "Администратор");
                }
            }

            _user = await userManager.FindByEmailAsync(userPatient.Email);

            if (_user == null)
            {
                var createUserPatient = await userManager.CreateAsync(userPatient, userPatient.Password);

                if (createUserPatient.Succeeded)
                {
                    var user = await userManager.FindByNameAsync(userPatient.UserName);

                    var patient = new Patient
                    {
                        UserID          = user.Id,
                        ApplicationUser = user
                    };

                    await context.Patients.AddAsync(patient);

                    await userManager.AddToRoleAsync(userPatient, "Пациент");
                }
            }

            _user = await userManager.FindByEmailAsync(userCalculator.Email);

            if (_user == null)
            {
                var createUserCalcuc = await userManager.CreateAsync(userCalculator, userCalculator.Password);

                if (createUserCalcuc.Succeeded)
                {
                    var user = await userManager.FindByNameAsync(userCalculator.UserName);

                    var employee = new Employee
                    {
                        ApplicationUser = user,
                        UserID          = user.Id
                    };

                    await context.Employees.AddAsync(employee);

                    await userManager.AddToRoleAsync(userCalculator, "Бухгалтер");
                }
            }

            var specialtities = new[]
            {
                new Specialty {
                    Name = "Нет специальности"
                },
                new Specialty {
                    Name = "Хирург"
                },
                new Specialty {
                    Name = "Косметолог"
                },
                new Specialty {
                    Name = "Физиотерапевт"
                },
                new Specialty {
                    Name = "Ревматолог"
                }
            };

            foreach (Specialty s in specialtities)
            {
                context.Add(s);
            }

            context.SaveChanges();

            var users = new ApplicationUser[]
            {
                new ApplicationUser {
                    Id = Guid.NewGuid(), Email = "*****@*****.**", UserName = "******", Password = "******", LastName = "Пупкин", FirstName = "Вася", MiddleName = "Васильевич", Gender = Gender.Мужской, Role = UserRole.Врач
                },
                new ApplicationUser {
                    Id = Guid.NewGuid(), Email = "*****@*****.**", UserName = "******", Password = "******", LastName = "Васильев", FirstName = "Вася", MiddleName = "Васильевич", Gender = Gender.Мужской, Role = UserRole.Врач
                },
                new ApplicationUser {
                    Id = Guid.NewGuid(), Email = "*****@*****.**", UserName = "******", Password = "******", LastName = "Ильин", FirstName = "Илья", MiddleName = "Ильич", Gender = Gender.Мужской, Role = UserRole.Врач
                },
                new ApplicationUser {
                    Id = Guid.NewGuid(), Email = "*****@*****.**", UserName = "******", Password = "******", LastName = "Петяев", FirstName = "Петя", MiddleName = "Петькович", Gender = Gender.Мужской, Role = UserRole.Врач
                }
            };

            foreach (ApplicationUser u in users)
            {
                context.Users.Add(u);
                await userManager.CreateAsync(u, u.Password);

                await userManager.AddToRoleAsync(u, UserRole.Врач.ToString());
            }

            context.SaveChanges();

            for (int i = 1; i < users.Length + 1; i++)
            {
                context.Employees.Add(new Employee {
                    UserID = users[i - 1].Id
                });
            }

            context.SaveChanges();

            var doctors = new Doctor[]
            {
                new Doctor {
                    EmployeeID = 3, SpecialtyID = context.Specialties.FirstOrDefault(s => s.Name == "Хирург").ID
                },
                new Doctor {
                    EmployeeID = 4, SpecialtyID = context.Specialties.FirstOrDefault(s => s.Name == "Косметолог").ID
                },
                new Doctor {
                    EmployeeID = 5, SpecialtyID = context.Specialties.FirstOrDefault(s => s.Name == "Физиотерапевт").ID
                },
                new Doctor {
                    EmployeeID = 6, SpecialtyID = context.Specialties.FirstOrDefault(s => s.Name == "Ревматолог").ID
                }
            };

            foreach (Doctor d in doctors)
            {
                context.Doctors.Add(d);
            }

            var services = new Service[]
            {
                new Service {
                    Name = "Прием ревматолога (первичный)", Price = 0, Description = "Прием", IsDeleted = false
                },
                new Service {
                    Name = "Прием ревматолога (вторичный)", Price = 600, Description = "Прием 2", IsDeleted = false
                }
            };

            foreach (Service s in services)
            {
                context.Services.Add(s);
            }

            context.SaveChanges();

            var doctorProvideServices = new DoctorProvideService[]
            {
                new DoctorProvideService {
                    DoctorID = 2, ServiceID = 1
                },
                new DoctorProvideService {
                    DoctorID = 2, ServiceID = 2
                }
            };

            foreach (DoctorProvideService dps in doctorProvideServices)
            {
                context.ProvideServices.Add(dps);
            }

            var dateOfAppointment = new DateOfAppointment[]
            {
                new DateOfAppointment {
                    DoctorID = 2, Date = DateTime.Today, PeriodOfWorking = "12-17"
                },
                new DateOfAppointment {
                    DoctorID = 2, Date = DateTime.Today.AddDays(1), PeriodOfWorking = "8-16"
                },
                new DateOfAppointment {
                    DoctorID = 2, Date = DateTime.Today.AddDays(3), PeriodOfWorking = "12-17"
                }
            };

            foreach (DateOfAppointment doa in dateOfAppointment)
            {
                context.AppointmentDates.Add(doa);
            }

            context.SaveChanges();
        }