<file_sep>﻿using System;


namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IServiceRepository : IRepository<DataModels.Services>
    {
        
        DataModels.Services GetServiceById(Guid serviceGuid);
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class AppointmentsService
    {
        private IAppointmentRepository appointmentRepository;
        public AppointmentsService(IAppointmentRepository appointmentRepository)
        {
            this.appointmentRepository = appointmentRepository;
        }
        public Appointment GetAppointmentById(string appointmentId)
        {
            Guid appointmentGuid = Guid.Empty;
            if (!Guid.TryParse(appointmentId, out appointmentGuid))
                throw new Exception("Invalid guid format");
            var appointment = appointmentRepository.GetAppointmentById(appointmentGuid);
            if (appointment == null)
                throw new EntityNotFoundException(appointmentGuid);
            return appointment;
        }
    }

}

<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IDoctorsRepository : IRepository<Doctor>
    {
        Doctor GetDoctorById(Guid id);
    }

}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class ClinicsServicesService
    {
        private IClinicServiceRepository clinicserviceRepository;
        public ClinicsServicesService(IClinicServiceRepository clinicserviceRepository)
        {
            this.clinicserviceRepository = clinicserviceRepository;
        }
        public ClinicServices GetClinicServiceById(string clinicserviceId)
        {
            Guid clinicserviceGuid = Guid.Empty;
            if (!Guid.TryParse(clinicserviceId, out clinicserviceGuid))
                throw new Exception("Invalid guid format");
            var clinicservice = clinicserviceRepository.GetServicesByClinicId(clinicserviceGuid);
            if (clinicservice == null)
                throw new EntityNotFoundException(clinicserviceGuid);
            return (ClinicServices)clinicservice;
        }
    }
}
<file_sep>﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace ShiningLight.DataAccess.Migrations
{
    public partial class InitialMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Services",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    Price = table.Column<decimal>(nullable: false),
                    Name = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Services", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    Name = table.Column<string>(nullable: true),
                    Password = table.Column<string>(nullable: true),
                    Email = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "Invoices",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    UserID = table.Column<Guid>(nullable: true),
                    Price = table.Column<decimal>(nullable: false),
                    PaymentMethod = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Invoices", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Invoices_Users_UserID",
                        column: x => x.UserID,
                        principalTable: "Users",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Clinics",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    AppointmentID = table.Column<Guid>(nullable: true),
                    Address = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Clinics", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "ClinicsServices",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    ServicesID = table.Column<Guid>(nullable: false),
                    ClinicID = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ClinicsServices", x => x.ID);
                    table.ForeignKey(
                        name: "FK_ClinicsServices_Clinics_ClinicID",
                        column: x => x.ClinicID,
                        principalTable: "Clinics",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ClinicsServices_Services_ServicesID",
                        column: x => x.ServicesID,
                        principalTable: "Services",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Doctors",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    ClinicID = table.Column<Guid>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    Qualification = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Doctors", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Doctors_Clinics_ClinicID",
                        column: x => x.ClinicID,
                        principalTable: "Clinics",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Appointments",
                columns: table => new
                {
                    ID = table.Column<Guid>(nullable: false),
                    UserID = table.Column<Guid>(nullable: true),
                    DoctorsID = table.Column<Guid>(nullable: true),
                    Type = table.Column<string>(nullable: true),
                    Prices = table.Column<decimal>(nullable: false),
                    ClinicID = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Appointments", x => x.ID);
                    table.ForeignKey(
                        name: "FK_Appointments_Clinics_ClinicID",
                        column: x => x.ClinicID,
                        principalTable: "Clinics",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Appointments_Doctors_DoctorsID",
                        column: x => x.DoctorsID,
                        principalTable: "Doctors",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Appointments_Users_UserID",
                        column: x => x.UserID,
                        principalTable: "Users",
                        principalColumn: "ID",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Appointments_ClinicID",
                table: "Appointments",
                column: "ClinicID");

            migrationBuilder.CreateIndex(
                name: "IX_Appointments_DoctorsID",
                table: "Appointments",
                column: "DoctorsID");

            migrationBuilder.CreateIndex(
                name: "IX_Appointments_UserID",
                table: "Appointments",
                column: "UserID");

            migrationBuilder.CreateIndex(
                name: "IX_Clinics_AppointmentID",
                table: "Clinics",
                column: "AppointmentID");

            migrationBuilder.CreateIndex(
                name: "IX_ClinicsServices_ClinicID",
                table: "ClinicsServices",
                column: "ClinicID");

            migrationBuilder.CreateIndex(
                name: "IX_ClinicsServices_ServicesID",
                table: "ClinicsServices",
                column: "ServicesID");

            migrationBuilder.CreateIndex(
                name: "IX_Doctors_ClinicID",
                table: "Doctors",
                column: "ClinicID");

            migrationBuilder.CreateIndex(
                name: "IX_Invoices_UserID",
                table: "Invoices",
                column: "UserID");

            migrationBuilder.AddForeignKey(
                name: "FK_Clinics_Appointments_AppointmentID",
                table: "Clinics",
                column: "AppointmentID",
                principalTable: "Appointments",
                principalColumn: "ID",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Appointments_Clinics_ClinicID",
                table: "Appointments");

            migrationBuilder.DropForeignKey(
                name: "FK_Doctors_Clinics_ClinicID",
                table: "Doctors");

            migrationBuilder.DropTable(
                name: "ClinicsServices");

            migrationBuilder.DropTable(
                name: "Invoices");

            migrationBuilder.DropTable(
                name: "Services");

            migrationBuilder.DropTable(
                name: "Clinics");

            migrationBuilder.DropTable(
                name: "Appointments");

            migrationBuilder.DropTable(
                name: "Doctors");

            migrationBuilder.DropTable(
                name: "Users");
        }
    }
}
<file_sep>﻿using Microsoft.EntityFrameworkCore;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class ShiningLightDBContext : DbContext
    {
        public ShiningLightDBContext (DbContextOptions<ShiningLightDBContext> options): base(options) { }

        public DbSet<Appointment> Appointments { get; set; }
        public DbSet<Clinic> Clinics { get; set; }
        public DbSet<ClinicServices> ClinicsServices { get; set; }

        public DbSet<Services> Services { get; set; }
        public DbSet<Doctor> Doctors { get; set; }
        public DbSet<Invoice> Invoices { get; set; }
        public DbSet<User> Users { get; set; }
    }
}<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class Services
    {
        public Guid ID { get; set; }
        public decimal Price { get; set; }
        public string Name { get; set; }
        public ICollection<ClinicServices> ClientServices { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class BaseRepository <T> : IRepository<T> where T : class,new()
    {
        protected readonly ShiningLightDBContext dbContext;
        public BaseRepository(ShiningLightDBContext dbContext)
        {
            this.dbContext = dbContext;
        }
        public T Add(T item)
        {
            var entity = dbContext.Add<T>(item);
            dbContext.SaveChanges();
            return entity.Entity;
        }

        public bool Delete(T item)
        {
            dbContext.Remove<T>(item);
            dbContext.SaveChanges();
            return true;
        }

        public IEnumerable<T> GetAll()
        {
            return dbContext.Set<T>()
                            .AsEnumerable();
        }

        public T Update(T item)
        {
            var entity = dbContext.Update<T>(item);
            dbContext.SaveChanges();
            return entity.Entity;
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class Invoice
    {
        public Guid ID { get; set; }
        public User User { get; set; }
        public decimal Price { get; set; }
        public string PaymentMethod { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class ServicesRepository : BaseRepository<Services>, IServiceRepository
    {
        public ServicesRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }

        public Services GetServiceById(Guid serviceGuid)
        {
            return dbContext.Services.Where(service => service.ID == serviceGuid).SingleOrDefault();
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class UsersRepository : BaseRepository<User>, IUserRepository
    {
        public UsersRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }

        public User GetUserById(Guid userGuid)
        {
            return dbContext.Users.Where(user => user.ID == userGuid).SingleOrDefault();
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class UsersService
    {
        private IUserRepository userRepository;
        public UsersService(IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }
        public User GetUserById(string userId)
        {
            Guid userGuid = Guid.Empty;
            if (!Guid.TryParse(userId, out userGuid))
                throw new Exception("Invalid guid format");
            var user = userRepository.GetUserById(userGuid);
            if (user == null)
                throw new EntityNotFoundException(userGuid);
            return user;
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class InvoicesService
    {
        private IInvoiceRepository invoiceRepository;
        public InvoicesService(IInvoiceRepository invoiceRepository)
        {
            this.invoiceRepository = invoiceRepository;
        }
        public Invoice GetInvoiceById(string invoiceId)
        {
            Guid invoiceGuid = Guid.Empty;
            if (!Guid.TryParse(invoiceId, out invoiceGuid))
                throw new Exception("Invalid guid format");
            var invoice = invoiceRepository.GetInvoicesById(invoiceGuid);
            if (invoice == null)
                throw new EntityNotFoundException(invoiceGuid);
            return invoice;
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IUserRepository : IRepository<User>
    {
        User GetUserById(Guid id);
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class DoctorsService
    {
        private IDoctorsRepository doctorRepository;
        public DoctorsService(IDoctorsRepository doctorRepository)
        {
            this.doctorRepository = doctorRepository;
        }
        public Doctor GetDoctorById(string doctorId)
        {
            Guid doctorGuid = Guid.Empty;
            if (!Guid.TryParse(doctorId, out doctorGuid))
                throw new Exception("Invalid guid format");
            var doctor = doctorRepository.GetDoctorById(doctorGuid);
            if (doctor == null)
                throw new EntityNotFoundException(doctorGuid);
            return doctor;
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class Appointment
    {
        public Guid ID { get; set; }
        public User User { get; set; }
        public Doctor Doctors { get; set; }

        public string Type { get; set; }
        public decimal Prices { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class ClinicRepository : BaseRepository<Clinic>, IClinicRepository
    {
        public ClinicRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }
        public Clinic GetClinicById(Guid id)
        {
            return dbContext.Clinics
                .Where(clinic => clinic.ID == id)
                .SingleOrDefault();
        }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class ClinicServices
    {
        public Guid ID { get; set; }
        public Guid ServicesID { get; set; }
        public Guid ClinicID { get; set; }
        public Services Services { get; set; }

        public Clinic Clinic { get; set; }
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class Doctor
    {
        public Guid ID { get; set; }
        public Clinic Clinic { get; set; }
        public string Name { get; set; }
        public string Qualification { get; set; }
        public ICollection<Appointment> Appointments { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class ServicesService
    {
        private IServiceRepository serviceRepository;
        public ServicesService(IServiceRepository serviceRepository)
        {
            this.serviceRepository = serviceRepository;
        }
        public DataModels.Services GetServiceById(string serviceId)
        {
            Guid serviceGuid = Guid.Empty;
            if (!Guid.TryParse(serviceId, out serviceGuid))
                throw new Exception("Invalid guid format");
            var service = serviceRepository.GetServiceById(serviceGuid);
            if (service == null)
                throw new EntityNotFoundException(serviceGuid);
            return service;
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class AppointmentRepository : BaseRepository <Appointment>, IAppointmentRepository
    {
        public AppointmentRepository(ShiningLightDBContext dbContext): base(dbContext)
        {

        }
        public Appointment GetAppointmentById(Guid id)
        {
            return dbContext.Appointments
                .Where(appointment => appointment.ID == id)
                .SingleOrDefault();
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class DoctorRepository : BaseRepository<Doctor>, IDoctorsRepository
    {
        public DoctorRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }

        public Doctor GetDoctorById(Guid id)
        {
            return dbContext.Doctors.Where(doctor => doctor.ID == id).SingleOrDefault();
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using ShinigLight.ApplicationLogic.Exceptions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Services
{
    public class ClinicsService
    {
        private IClinicRepository clinicRepository;
        public ClinicsService(IClinicRepository clinicRepository)
        {
            this.clinicRepository = clinicRepository;
        }
        public Clinic GetClinicById(string clinicId)
        {
            Guid clinicGuid = Guid.Empty;
            if (!Guid.TryParse(clinicId, out clinicGuid))
                throw new Exception("Invalid guid format");
            var clinic = clinicRepository.GetClinicById(clinicGuid);
            if (clinic == null)
                throw new EntityNotFoundException(clinicGuid);
            return clinic;
        }
    }
}
<file_sep># ShiningLight
Detist website 
<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Abstractions
{
  
        public interface IClinicServiceRepository : IRepository<ClinicServices>
        {
           IEnumerable<ClinicServices> GetServicesByClinicId(Guid clinicId);
         
        }

}
<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IClinicRepository : IRepository<Clinic>
    {
        Clinic GetClinicById(Guid id);
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class Clinic
    {
        public Guid ID { get; set; }
        public Appointment Appointment { get; set; }
        public string Address { get; set; }
        public ICollection<Appointment> Appointments { get; set; }
        public ICollection<ClinicServices> Client_Services { get; set; }
        public ICollection<Doctor> Doctors { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IInvoiceRepository : IRepository<Invoice>
    {
        Invoice GetInvoicesById(Guid id);
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.DataModels;
using System;


namespace ShinigLight.ApplicationLogic.Abstractions
{
    public interface IAppointmentRepository : IRepository<Appointment>
    {
        Appointment GetAppointmentById(Guid id);
    }
}
<file_sep>﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ShinigLight.ApplicationLogic.DataModels
{
    public class User
    {
        public Guid ID { get; set; }
        public string Name { get; set; }
        public string Password { get; set; }
        public string Email { get; set; }
        public ICollection<Appointment> Appointments { get; set; }
        public ICollection<Invoice> Invoices { get; set; }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class InvoicesRepository : BaseRepository<Invoice>, IInvoiceRepository
    {
        public InvoicesRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }
        public Invoice GetInvoicesById(Guid id)
        {
            return dbContext.Invoices.Where(invoice => invoice.ID == id).SingleOrDefault();
        }
    }
}
<file_sep>﻿using ShinigLight.ApplicationLogic.Abstractions;
using ShinigLight.ApplicationLogic.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShiningLight.DataAccess
{
    public class ClinicServicesRepository : BaseRepository<ClinicServices>, IClinicServiceRepository
    {
        public ClinicServicesRepository(ShiningLightDBContext dbContext) : base(dbContext)
        {

        }

        public IEnumerable<ClinicServices> GetServicesByClinicId(Guid clinicId)
        {
            return dbContext.ClinicsServices
                .Where(clinicServices => clinicServices.ClinicID == clinicId)
                .AsEnumerable();
        }
    }
}
