Changeset 63d885e for FarmatikoData


Ignore:
Timestamp:
08/07/20 11:01:25 (4 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
5d02859
Parents:
ee137aa (diff), c406ae5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://develop.finki.ukim.mk/git/farmatiko

Location:
FarmatikoData
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoData/FarmatikoRepo/HealthFacilityRepository.cs

    ree137aa r63d885e  
    1616        public void Add(HealthFacilities healthFacility)
    1717        {
    18             _context.Add(healthFacility);
    19             _context.SaveChanges();
     18             _context.HealthFacilities.Add(healthFacility);
     19            _context.SaveChangesAsync();
    2020        }
    2121
    2222        public IQueryable<HealthFacilities> GetAll()
    2323        {
    24             return _context.HealthFacilities.OrderBy(x => x.Name);
     24            return _context.HealthFacilities.Take(50).Select(x => new HealthFacilities
     25            {
     26                Name = x.Name,
     27                Municipality = x.Municipality,
     28                Address = x.Address,
     29                Type = x.Type,
     30                Email = x.Email,
     31                Phone = x.Phone
     32            }).OrderBy(x => x.Name);
     33        }
     34
     35        public IQueryable<HealthFacilities> GetByName(string Name)
     36        {
     37            return _context.HealthFacilities.Where(x => x.Name.Equals(Name));
    2538        }
    2639
    2740        public void Remove(HealthFacilities healthFacility)
    2841        {
    29             var facility = _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility.Name));
    30             _context.HealthFacilities.Remove((HealthFacilities)facility);
     42            var facility = _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility.Name)).FirstOrDefault();
     43            if (facility != null)
     44            {
     45                _context.HealthFacilities.Remove(facility);
     46                _context.SaveChangesAsync();
     47            }
     48           
    3149        }
    3250    }
  • FarmatikoData/FarmatikoRepo/HealthcareWorkerRepository.cs

    ree137aa r63d885e  
    22using FarmatikoData.Models;
    33using System.Linq;
     4using System.Threading.Tasks;
    45
    56namespace FarmatikoData.FarmatikoRepo
     
    2324        public IQueryable<HealthcareWorkers> GetAll()
    2425        {
    25             return _context.HealthcareWorkers.OrderBy(x => x.Name);
     26            return _context.HealthcareWorkers.Take(50).Select(x => new HealthcareWorkers
     27            {
     28                Name = x.Name,
     29                Branch = x.Branch,
     30                Facility = x.Facility,
     31                Title = x.Title
     32            }).OrderBy(x => x.Name);
    2633        }
    2734
    2835        public void Remove(HealthcareWorkers healthcareWorker)
    2936        {
    30             var healthCareWorker = _context.HealthcareWorkers.Where(x => x.Name.Equals(healthcareWorker.Name));
    31             _context.HealthcareWorkers.Remove((HealthcareWorkers)healthCareWorker);
     37            var healthCareWorker = _context.HealthcareWorkers.Where(x => x.Name.Equals(healthcareWorker.Name)).FirstOrDefault();
     38            if (healthCareWorker != null)
     39            {
     40                _context.HealthcareWorkers.Remove(healthCareWorker);
     41                _context.SaveChangesAsync();
     42            }
     43           
    3244        }
    3345    }
  • FarmatikoData/FarmatikoRepo/MedicineListRepository.cs

    ree137aa r63d885e  
    2929        public IQueryable<MedicineList> GetAll()
    3030        {
    31             return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
     31            return _context.MedicineLists.Take(50).Select(x => new MedicineList
     32            {
     33                Medicine = x.Medicine,
     34                HasMedicine = x.HasMedicine
     35            }).OrderBy(x => x.Medicine.Name);
    3236        }
    3337
    3438        public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
    3539        {
    36             return (ICollection<MedicineList>)_context.MedicineLists
     40            return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
    3741                .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
     42                .Select(x => new MedicineList
     43                {
     44                    Medicine = x.Medicine,
     45                    HasMedicine = x.HasMedicine
     46                })
    3847                .OrderBy(x => x.Medicine.Name)
    3948                .Cast<ICollection<MedicineList>>();
     
    4150        public ICollection<MedicineList> GetByName(string Name)
    4251        {
    43             return (ICollection<MedicineList>)_context.MedicineLists
     52            return (ICollection<MedicineList>)_context.MedicineLists.Take(50)
    4453                .Where(x => x.Medicine.Name.Contains(Name))
     54                .Select(x => new MedicineList
     55                {
     56                    Medicine = x.Medicine,
     57                    HasMedicine = x.HasMedicine
     58                })
    4559                .OrderBy(x => x.Medicine.Name)
    4660                .Cast<ICollection<MedicineList>>();
     
    4963        public void Remove(MedicineList medicineList)
    5064        {
    51             var list = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
    52             _context.MedicineLists.Remove(list);
     65            var list = _context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine)).FirstOrDefault();
     66            if (list != null)
     67            {
     68                _context.MedicineLists.Remove(list);
     69                _context.SaveChangesAsync();
     70            }
    5371        }
    5472    }
  • FarmatikoData/FarmatikoRepo/MedicineRepository.cs

    ree137aa r63d885e  
    2121        public IQueryable<Medicine> GetAll()
    2222        {
    23             return _context.Medicines.OrderBy(x => x.Name);
     23            return _context.Medicines.Take(50).Select(x => new Medicine
     24            {
     25                Name = x.Name,
     26                Strength = x.Strength,
     27                Form = x.Form,
     28                WayOfIssuing = x.WayOfIssuing,
     29                Manufacturer = x.Manufacturer,
     30                Price = x.Price,
     31                Packaging = x.Packaging
     32            }).OrderBy(x => x.Name);
    2433        }
    2534
    2635        public IQueryable<Medicine> GetByManufacturer(string Manufacturer)
    2736        {
    28             return _context.Medicines.Where(x => x.Name.Contains(Manufacturer)).OrderBy(x => x.Manufacturer);
     37            return _context.Medicines.Take(50).Where(x => x.Name.Contains(Manufacturer))
     38                .Select(x => new Medicine
     39                {
     40                    Name = x.Name,
     41                    Strength = x.Strength,
     42                    Form = x.Form,
     43                    WayOfIssuing = x.WayOfIssuing,
     44                    Manufacturer = x.Manufacturer,
     45                    Price = x.Price,
     46                    Packaging = x.Packaging
     47                }).OrderBy(x => x.Manufacturer);
    2948        }
    3049
    3150        public IQueryable<Medicine> GetByName(string Name)
    3251        {
    33             return _context.Medicines.Where(medicine => medicine.Name.Contains(Name)).OrderBy(x => x.Name);
     52            return _context.Medicines.Take(50).Where(medicine => medicine.Name.Contains(Name))
     53                .Select(x => new Medicine
     54                {
     55                    Name = x.Name,
     56                    Strength = x.Strength,
     57                    Form = x.Form,
     58                    WayOfIssuing = x.WayOfIssuing,
     59                    Manufacturer = x.Manufacturer,
     60                    Price = x.Price,
     61                    Packaging = x.Packaging
     62                }).OrderBy(x => x.Name);
    3463        }
    3564
    36         public void Remove(string medicine)
     65        public void Remove(Medicine medicine)
    3766        {
    38             Medicine med = (Medicine)_context.Medicines.Where(medicine => medicine.Name.Equals(medicine));
    39             _context.Medicines.Remove(med);
     67            Medicine med = _context.Medicines.Where(medicine => medicine.Name.Equals(medicine.Name)).FirstOrDefault();
     68            if (med != null)
     69            {
     70                _context.Medicines.Remove(med);
     71                _context.SaveChangesAsync();
     72            }
     73
    4074        }
    4175    }
  • FarmatikoData/FarmatikoRepo/PandemicRepository.cs

    ree137aa r63d885e  
    2222        public IQueryable<Pandemic> GetAll()
    2323        {
    24             return _context.Pandemics.OrderBy(x => x.Name);
     24            return _context.Pandemics.Select(x => new Pandemic
     25            {
     26                Name = x.Name,
     27                TotalMK = x.TotalMK,
     28                ActiveMK = x.ActiveMK,
     29                DeathsMK = x.DeathsMK,
     30                NewMK = x.NewMK,
     31                TotalGlobal = x.TotalGlobal,
     32                DeathsGlobal = x.DeathsGlobal,
     33                ActiveGlobal = x.ActiveGlobal
     34            }).OrderBy(x => x.Name);
    2535        }
    2636
    2737        public void Remove(Pandemic pandemic)
    2838        {
    29             _context.Pandemics.Remove(pandemic);
    30             _context.SaveChangesAsync();
     39            var Pandem = _context.Pandemics.Where(x => x.Name.Equals(pandemic.Name)).FirstOrDefault();
     40            if (Pandem != null)
     41            {
     42                _context.Pandemics.Remove(Pandem);
     43                _context.SaveChangesAsync();
     44            }
    3145        }
    3246    }
  • FarmatikoData/FarmatikoRepo/PharmacyHeadRepository.cs

    ree137aa r63d885e  
    2222        public IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacyHeads)
    2323        {
    24             return _context.PharmacyHeads
    25                 .Where(pharmacyHead => pharmacyHead.Name.Contains(NameOfPharmacyHeads))
    26                 .OrderBy(x => x.Name);
     24            return _context.PharmacyHeads.Where(pharmacyHead => pharmacyHead.Name.Contains(NameOfPharmacyHeads))
     25                .Take(10).Select(x => new PharmacyHead
     26                {
     27                    MedicineLists = x.MedicineLists,
     28                    PharmaciesList = x.PharmaciesList,
     29                    Email = x.Email,
     30                    Name = x.Name,
     31                }).OrderBy(x => x.Name);
    2732        }
    2833        //Not needed
    2934        public IQueryable<PharmacyHead> GetPharmacyByName(string Name)
    3035        {
    31             return _context.PharmacyHeads.Where(pharmacyHead => pharmacyHead.Name.Equals(Name));
     36            return _context.PharmacyHeads.Take(10)
     37                .Where(pharmacyHead => pharmacyHead.Name.Equals(Name))
     38                .Select(x => new PharmacyHead
     39                {
     40                    MedicineLists = x.MedicineLists,
     41                    PharmaciesList = x.PharmaciesList,
     42                    Email = x.Email,
     43                    Name = x.Name,
     44                }).OrderBy(x => x.Name);
    3245        }
    3346
     
    3548        {
    3649
    37             IQueryable<MedicineList> Pharmacy = (IQueryable<MedicineList>)_context.PharmacyHeads.Where(x => x.Name.Equals(NameOfPharmacy));
    38            
     50            IQueryable<MedicineList> Pharmacy = (IQueryable<MedicineList>)_context.PharmacyHeads
     51                .Take(50)
     52                .Where(x => x.Name.Equals(NameOfPharmacy))
     53                .Select(x => new PharmacyHead
     54                {
     55                    MedicineLists = x.MedicineLists
     56                }).OrderBy(x => x.Name);
     57
    3958            return Pharmacy;
    4059        }
    4160
    42         public void Remove(PharmacyHead pharmacyHead, string Name)
     61        public void Remove(PharmacyHead pharmacyHead)
    4362        {
    44             var phead = (PharmacyHead)_context.PharmacyHeads.Where(phead => phead.Name.Equals(Name)).FirstOrDefault();
    45             _context.PharmacyHeads.Remove(phead);
    46             _context.SaveChangesAsync();
     63            var phead = _context.PharmacyHeads.Where(phead => phead.Name.Equals(pharmacyHead.Name)).FirstOrDefault();
     64            if (phead != null)
     65            {
     66                _context.PharmacyHeads.Remove(phead);
     67                _context.SaveChangesAsync();
     68            }
    4769        }
    4870    }
  • FarmatikoData/FarmatikoRepo/PharmacyRepository.cs

    ree137aa r63d885e  
    11using FarmatikoData.FarmatikoRepoInterfaces;
    22using FarmatikoData.Models;
     3using System;
    34using System.Collections.Generic;
    45using System.Linq;
     
    1819        {
    1920            _context.Pharmacies.Add(pharmacy);
    20             _context.SaveChangesAsync();
     21            _context.SaveChanges();
    2122        }
    2223        //Just for users
    2324        public IQueryable<Pharmacy> GetAll()
    2425        {
    25             return _context.Pharmacies.OrderBy(x => x.Name);
     26            return _context.Pharmacies.Take(50)
     27                .Select(x => new Pharmacy
     28                {
     29                    Name = x.Name,
     30                    Location = x.Location,
     31                    Address = x.Address,
     32                    WorkAllTime = x.WorkAllTime
     33                }).OrderBy(x => x.Name);
    2634        }
    2735
    2836        public ICollection<Pharmacy> GetPharmacies()
    2937        {
    30             return (ICollection<Pharmacy>)_context.Pharmacies.Select(pharmacy => new
    31             {
    32                 pharmacy.Name,
    33                 pharmacy.Address,
    34                 pharmacy.Location,
    35                 pharmacy.WorkAllTime
    36             }).OrderBy(x => x.Name);
     38            return (ICollection<Pharmacy>)_context.Pharmacies.Take(50)
     39                .Select(pharmacy => new
     40                {
     41                    pharmacy.Name,
     42                    pharmacy.Address,
     43                    pharmacy.Location,
     44                    pharmacy.WorkAllTime
     45                }).OrderBy(x => x.Name);
    3746        }
    3847
    3948        public void Remove(Pharmacy pharmacy)
    4049        {
    41             var pharma = _context.Pharmacies.Where(pharm => pharm.Name.Equals(pharmacy.Name)).Cast<Pharmacy>();
    42             _context.Pharmacies.Remove((Pharmacy)pharma);
    43             _context.SaveChangesAsync();
     50            var pharma = _context.Pharmacies.Where(pharm => pharm.Name.Equals(pharmacy.Name)).FirstOrDefault();
     51            if (pharma != null)
     52            {
     53                _context.Pharmacies.Remove(pharmacy);
     54                _context.SaveChangesAsync();
     55            }
    4456        }
    4557
    46         public void UpdatePharmacy(Pharmacy pharmacy, string Name)
     58        public void UpdatePharmacy(Pharmacy pharmacy)
    4759        {
    48             var oldPharmacy = _context.Pharmacies.Where(pharma => pharma.Name.Equals(Name)).Cast<Pharmacy>();
    49             _context.Pharmacies.Remove((Pharmacy)oldPharmacy);
    50             _context.Pharmacies.Add(pharmacy);
    51             _context.SaveChangesAsync();
     60            var oldPharmacy = _context.Pharmacies.Where(pharma => pharma.Name.Equals(pharmacy.Name)).FirstOrDefault();
     61            if (oldPharmacy != null)
     62            {
     63                _context.Pharmacies.Remove(oldPharmacy);
     64                _context.Pharmacies.Add(pharmacy);
     65                _context.SaveChangesAsync();
     66            }
     67            throw new Exception("Pharmacy not found");
    5268        }
    5369    }
  • FarmatikoData/FarmatikoRepoInterfaces/IHealthFacilityRepository.cs

    ree137aa r63d885e  
    99        void Add(HealthFacilities healthFacility);
    1010        void Remove(HealthFacilities healthFacility);
     11        IQueryable<HealthFacilities> GetByName(string Name);
    1112    }
    1213}
  • FarmatikoData/FarmatikoRepoInterfaces/IMedicineRepository.cs

    ree137aa r63d885e  
    99        IQueryable<Medicine> GetByName(string Name);
    1010        void Add(Medicine medicine);
    11         void Remove(string medicine);
     11        void Remove(Medicine medicine);
    1212        IQueryable<Medicine> GetByManufacturer(string Manufacturer);
    1313
  • FarmatikoData/FarmatikoRepoInterfaces/IPharmacyHeadRepository.cs

    ree137aa r63d885e  
    77    {
    88        void Add(PharmacyHead pharmacyHead);
    9         void Remove(PharmacyHead pharmacyHead, string Name);
     9        void Remove(PharmacyHead pharmacyHead);
    1010        IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacyHead);
    1111        //Not actually needed
  • FarmatikoData/FarmatikoRepoInterfaces/IPharmacyRepository.cs

    ree137aa r63d885e  
    1111        IQueryable<Pharmacy> GetAll();
    1212        void Remove(Pharmacy pharmacy);
    13         void UpdatePharmacy(Pharmacy pharmacy, string Name);
     13        void UpdatePharmacy(Pharmacy pharmacy);
    1414
    1515    }
  • FarmatikoData/Models/HealthFacilities.cs

    ree137aa r63d885e  
    2222        public string Email { get; set; }
    2323        public string Phone { get; set; }
     24        public HealthFacilities(string Name, string Municipality, string Address, string Type, string Email, string Phone)
     25        {
     26            this.Name = Name;
     27            this.Municipality = Municipality;
     28            this.Address = Address;
     29            this.Type = Type;
     30            this.Email = Email;
     31            this.Phone = Phone;
     32        }
    2433    }
    2534}
  • FarmatikoData/Models/HealthcareWorkers.cs

    ree137aa r63d885e  
    1818        public HealthFacilities Facility { get; set; }
    1919        public string Title { get; set; }
     20        public HealthcareWorkers(string Name, string Branch, HealthFacilities Facility, string Title)
     21        {
     22            this.Name = Name;
     23            this.Branch = Branch;
     24            this.Facility = Facility;
     25            this.Title = Title;
     26        }
    2027    }
    2128}
  • FarmatikoData/Models/Medicine.cs

    ree137aa r63d885e  
    1313        public float Price { get; set; }
    1414        public string Packaging { get; set; }
     15        public Medicine(string Name, string Strength, string Form, string WayOfIssuing, string Manufacturer, float Price, string Packaging)
     16        {
     17            this.Name = Name;
     18            this.Strength = Strength;
     19            this.Form = Form;
     20            this.WayOfIssuing = WayOfIssuing;
     21            this.Manufacturer = Manufacturer;
     22            this.Price = Price;
     23            this.Packaging = Packaging;
     24        }
    1525
    1626    }
  • FarmatikoData/Models/MedicineList.cs

    ree137aa r63d885e  
    88    public class MedicineList : BaseEntity
    99    {
     10        public MedicineList()
     11        {
     12        }
    1013        public Medicine Medicine { get; set; }
    1114        public bool HasMedicine { get; set; }
     15        public MedicineList(Medicine Medicine, bool HasMedicine)
     16        {
     17            this.Medicine = Medicine;
     18            this.HasMedicine = HasMedicine;
     19        }
    1220        /*public ICollection<MedicineList> MedicinesList { get; set; }
    1321        public MedicineList()
  • FarmatikoData/Models/Pharmacy.cs

    ree137aa r63d885e  
    1414        public string Address { get; set; }
    1515        public bool WorkAllTime { get; set; }
     16        public Pharmacy(string Name, string Location, string Address, bool WorkAllTime)
     17        {
     18            this.Name = Name;
     19            this.Location = Location;
     20            this.Address = Address;
     21            this.WorkAllTime = WorkAllTime;
     22        }
    1623    }
    1724}
Note: See TracChangeset for help on using the changeset viewer.