public async Task <bool> CreateRoomType(RoomTypeServiceModel roomTypeServiceModel)
        {
            var roomTypeFromDb = await context.RoomTypes.SingleOrDefaultAsync(x => x.Name == roomTypeServiceModel.Name);

            if (roomTypeFromDb != null)
            {
                roomTypeFromDb.Name        = roomTypeServiceModel.Name;
                roomTypeFromDb.PriceForBed = roomTypeServiceModel.PriceForBed;
                roomTypeFromDb.IsDeleted   = false;
                roomTypeFromDb.DeletedOn   = null;

                context.RoomTypes.Update(roomTypeFromDb);
                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            else
            {
                RoomType roomType = AutoMapper.Mapper.Map <RoomType>(roomTypeServiceModel);

                context.RoomTypes.Add(roomType);
                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
        }
        public async Task <bool> Create(string password, PatientServiceModel patientServiceModel)
        {
            var user = new HospitalMSUser {
                UserName = patientServiceModel.Email, Email = patientServiceModel.Email
            };
            var userCreateResult = await userManager.CreateAsync(user, password);

            if (userCreateResult.Succeeded)
            {
                user.EmailConfirmed = true;
                user.IsFirstLogin   = false;

                await userManager.AddToRoleAsync(user, GlobalConstants.PatientRoleName);
            }

            patientServiceModel.HospitalMSUserId = user.Id;

            Patient patient = AutoMapper.Mapper.Map <Patient>(patientServiceModel);

            context.Patients.Add(patient);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 3
0
        public async Task <bool> Create(string password, DoctorServiceModel doctorServiceModel)
        {
            var user = new HospitalMSUser {
                UserName = doctorServiceModel.Email, Email = doctorServiceModel.Email
            };
            var userCreateResult = await userManager.CreateAsync(user, password);

            if (userCreateResult.Succeeded)
            {
                user.EmailConfirmed = true;
                user.IsFirstLogin   = false;

                await userManager.AddToRoleAsync(user, GlobalConstants.DoctorRoleName);
            }

            Department departmentFromDb = await GetDepartmentFromDb(doctorServiceModel);

            if (departmentFromDb == null)
            {
                throw new ArgumentNullException(nameof(departmentFromDb));
            }

            doctorServiceModel.HospitalMSUserId = user.Id;

            Doctor doctor = AutoMapper.Mapper.Map <Doctor>(doctorServiceModel);

            doctor.Department = departmentFromDb;
            context.Doctors.Add(doctor);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task <bool> Create(string password, ReceptionistServiceModel receptionistServiceModel)
        {
            var user = new HospitalMSUser {
                UserName = receptionistServiceModel.Email, Email = receptionistServiceModel.Email
            };
            var userCreateResult = await userManager.CreateAsync(user, password);

            if (userCreateResult.Succeeded)
            {
                user.EmailConfirmed = true;
                user.IsFirstLogin   = false;

                await userManager.AddToRoleAsync(user, GlobalConstants.ReceptionistRoleName);
            }

            Hospital hospitalFromDb = await GetHospitalFromDb(receptionistServiceModel);

            if (hospitalFromDb == null)
            {
                throw new ArgumentNullException(nameof(hospitalFromDb));
            }

            receptionistServiceModel.HospitalMSUserId = user.Id;

            Receptionist receptionist = AutoMapper.Mapper.Map <Receptionist>(receptionistServiceModel);

            receptionist.Hospital = hospitalFromDb;
            context.Receptionists.Add(receptionist);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task SeedAsync(HospitalMSDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(HospitalMSDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new RolesSeeder(),
                new RootSeeder(),
                new HospitalSeeder()
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
Esempio n. 6
0
        public async Task <bool> CreateDiagnose(string patientId, string doctorId, DiagnoseServiceModel diagnoseServiceModel)
        {
            Patient patientFromDb = await context.Patients.SingleOrDefaultAsync(patient => patient.Id == patientId);

            if (patientFromDb == null)
            {
                throw new ArgumentNullException(nameof(patientFromDb));
            }

            Doctor doctorFromDb = await context.Doctors.SingleOrDefaultAsync(doctor => doctor.HospitalMSUserId == doctorId);

            if (doctorFromDb == null)
            {
                throw new ArgumentNullException(nameof(doctorFromDb));
            }

            Diagnose diagnose = AutoMapper.Mapper.Map <Diagnose>(diagnoseServiceModel);

            diagnose.Date    = DateTime.UtcNow;
            diagnose.Patient = patientFromDb;
            diagnose.Doctor  = doctorFromDb;

            context.Diagnoses.Add(diagnose);

            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 7
0
        public async Task <bool> Create(RoomServiceModel roomServiceModel)
        {
            RoomType roomTypeFromDb = await GetRoomTypeFromDb(roomServiceModel);

            if (roomTypeFromDb == null)
            {
                throw new ArgumentNullException(nameof(roomTypeFromDb));
            }

            Department departmentFromDb = await GetDepartmentFromDb(roomServiceModel);

            if (departmentFromDb == null)
            {
                throw new ArgumentNullException(nameof(departmentFromDb));
            }
            var roomFromDb = await context.Rooms.SingleOrDefaultAsync(x => x.Name == roomServiceModel.Name);

            if (roomFromDb != null)
            {
                roomFromDb.Name = roomServiceModel.Name;

                roomFromDb.IsDeleted  = false;
                roomFromDb.DeletedOn  = null;
                roomFromDb.RoomType   = roomTypeFromDb;
                roomFromDb.Department = departmentFromDb;

                context.Rooms.Update(roomFromDb);
                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            else
            {
                Room room = AutoMapper.Mapper.Map <Room>(roomServiceModel);
                room.RoomType   = roomTypeFromDb;
                room.Department = departmentFromDb;

                context.Rooms.Add(room);
                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
        }
Esempio n. 8
0
        public async Task <bool> Create(DepartmentServiceModel departmentServiceModel)
        {
            Hospital hospitalFromDb = await GetHospital(departmentServiceModel);

            if (hospitalFromDb == null)
            {
                throw new ArgumentNullException(nameof(hospitalFromDb));
            }

            var departmentFromDb = await context.Departments.SingleOrDefaultAsync(x => x.Name == departmentServiceModel.Name);

            if (departmentFromDb != null)
            {
                departmentFromDb.Name        = departmentServiceModel.Name;
                departmentFromDb.Description = departmentServiceModel.Description;
                departmentFromDb.IsActive    = departmentServiceModel.IsActive;
                departmentFromDb.IsDeleted   = false;
                departmentFromDb.DeletedOn   = null;
                departmentFromDb.Hospital    = hospitalFromDb;

                context.Departments.Update(departmentFromDb);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            else
            {
                Department department = AutoMapper.Mapper.Map <Department>(departmentServiceModel);

                department.Hospital = hospitalFromDb;

                context.Departments.Add(department);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
        }
Esempio n. 9
0
        public async Task <bool> Create(string roomId, BedServiceModel bedServiceModel)
        {
            Room roomFromDb = await context.Rooms.SingleOrDefaultAsync(room => room.Id == roomId);

            if (roomFromDb == null)
            {
                throw new ArgumentNullException(nameof(roomFromDb));
            }

            Bed bedFromDb = await context.Beds.FirstOrDefaultAsync(bed => bed.Number == bedServiceModel.Number);

            if (bedFromDb != null && bedFromDb.IsDeleted == true)
            {
                bedFromDb.Number = bedServiceModel.Number;

                bedFromDb.IsDeleted = false;
                bedFromDb.DeletedOn = null;

                bedFromDb.Room = roomFromDb;

                context.Beds.Update(bedFromDb);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            else
            {
                Bed bed = AutoMapper.Mapper.Map <Bed>(bedServiceModel);

                bed.Room = roomFromDb;

                context.Beds.Add(bed);

                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
        }
Esempio n. 10
0
        public async Task SeedAsync(HospitalMSDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.Hospitals.Any())
            {
                var hospital = new Hospital
                {
                    Name        = GlobalConstants.HospitalName,
                    Address     = GlobalConstants.HospitalAddress,
                    Email       = GlobalConstants.HospitalEmail,
                    PhoneNumber = GlobalConstants.HospitalPhone,
                };

                await dbContext.Hospitals.AddAsync(hospital);

                await dbContext.SaveChangesAsync();
            }
        }
Esempio n. 11
0
        public async Task <bool> Edit(string id, HospitalServiceModel hospitalServiceModel)
        {
            Hospital hospitalFromDb = await context.Hospitals.SingleOrDefaultAsync(hospital => hospital.Id == id);

            if (hospitalFromDb == null)
            {
                throw new ArgumentNullException(nameof(hospitalFromDb));
            }

            hospitalFromDb.Name        = hospitalServiceModel.Name;
            hospitalFromDb.Address     = hospitalServiceModel.Address;
            hospitalFromDb.Email       = hospitalServiceModel.Email;
            hospitalFromDb.PhoneNumber = hospitalServiceModel.PhoneNumber;


            context.Hospitals.Update(hospitalFromDb);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }