Changeset 1db5673 for FarmatikoServices


Ignore:
Timestamp:
11/14/20 12:27:30 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
68454c6
Parents:
ad60966
Message:

Fix bugs, add some more

Location:
FarmatikoServices
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs

    rad60966 r1db5673  
    1818        Task<bool> Remove(int id);
    1919        Task<bool> RemoveClaimingRequest(int id);
    20         PharmacyHead GetPharmacyHead(string userName);
     20        object GetPharmacyHead(string userName);
    2121    }
    2222}
  • FarmatikoServices/Services/PHService.cs

    rad60966 r1db5673  
    1313    {
    1414        private readonly IPHRepo _iPHRepo;
    15         public PHService(IPHRepo iPHRepo)
     15        private readonly IRepository _repository;
     16        public PHService(IPHRepo iPHRepo, IRepository repository)
    1617        {
    1718            _iPHRepo = iPHRepo;
     19            _repository = repository;
    1820        }
    1921
     
    5557
    5658
     59
    5760        public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)
    5861        {
    5962            if (pharmacyHead != null)
    60                 await _iPHRepo.UpdatePharmacyHead(pharmacyHead);
     63            {
     64                var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email);
     65
     66                if (pharmacyHead.PharmaciesList.Count() == 0)
     67                    pharmacyHead.PharmaciesList = null;
     68                if (pharmacyHead.MedicineList.Count() == 0)
     69                    pharmacyHead.MedicineList = null;
     70
     71                phead.PHMedicineList = _repository.GetPHMedicines(phead.Email);
     72
     73                if (phead.MedicineList != pharmacyHead.MedicineList || phead != pharmacyHead)
     74                {
     75                    phead.MedicineList = pharmacyHead.MedicineList;
     76                    List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>();
     77
     78                    foreach (var med in phead.MedicineList)
     79                    {
     80                        med.Id++;
     81                        var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine
     82                        {
     83                            PheadId = x.PheadId,
     84                            Head = x.Head,
     85                            MedicineId = x.MedicineId,
     86                            Medicine = x.Medicine
     87                        }).Where(x => x.MedicineId == med.Id).Single();
     88                        list.Add(PHMObj);
     89                    }
     90
     91                    phead.PHMedicineList = list;
     92
     93                    await _iPHRepo.UpdatePharmacyHead(phead);
     94                }
     95                else throw new Exception("Cannot update pharmacy head since there was no changes.");
     96            }
    6197            else throw new Exception("PharmacyHead has a null value.");
    6298        }
     
    93129        }
    94130
    95         public PharmacyHead GetPharmacyHead(string userName)
     131        public object GetPharmacyHead(string userName)
    96132        {
    97133            if (userName != null)
    98134            {
    99                 return _iPHRepo.GetPharmacyHeadByUserName(userName);
    100             }
    101             return default;
     135                var Phead = _iPHRepo.GetPharmacyHeadByUserName(userName);
     136                List<PharmacyHeadMedicine> PHMedicines = _iPHRepo.GetPharmacyHeadMedicines(userName);
     137                List<Medicine> Medicines = _repository.GetMedicines().ToList();
     138                List<Medicine> PHMedicineList = new List<Medicine>();
     139
     140
     141                //var meds = PHMedicines.Where(x => x.Id == Phead.Id).ToList();
     142                var pharmacies = _iPHRepo.GetPharmacies();
     143                var PheadPharms = pharmacies.Where(x => x.PheadId == Phead.Id).ToList();
     144                var user = _repository.GetRole(userName);
     145
     146
     147                if (user.UserRole.ToString().Equals("Admin"))
     148                {
     149                    var Admin = new
     150                    {
     151                        Id = user.Id,
     152                        Email = user.Email,
     153                        Name = user.Name,
     154                        Passwd = user.Password,
     155                        MedicineList = PHMedicines,
     156                        PharmaciesList = Phead.PharmaciesList
     157                    };
     158
     159                    return Admin;
     160                }
     161
     162                if (PheadPharms.Count() > 0)
     163                    Phead.MedicineList = PHMedicineList;
     164                else Phead.PharmaciesList = pharmacies;
     165
     166                if (Phead.PHMedicineList.Count() > 0)
     167                {
     168                    foreach (var med in Medicines)
     169                    {
     170                        var PHMObj = Phead.PHMedicineList.Select(x => new PharmacyHeadMedicine
     171                        {
     172                            PheadId = x.PheadId,
     173                            Head = x.Head,
     174                            MedicineId = x.MedicineId,
     175                            Medicine = x.Medicine
     176                        }).Where(x => x.MedicineId == med.Id).SingleOrDefault();
     177                        if (PHMObj == null || PHMObj == default)
     178                            break;
     179                        if (PHMObj.MedicineId == med.Id)
     180                        {
     181                            Medicine medicine = new Medicine(med.Name, med.Strength, med.Form, med.WayOfIssuing, med.Manufacturer, med.Price, med.Packaging);
     182                            PHMedicineList.Add(medicine);
     183                        }
     184                    }
     185                    Phead.MedicineList = PHMedicineList;
     186                }
     187                else
     188                {
     189                    Phead.MedicineList = Medicines;
     190                }
     191
     192                PharmacyHead pharHead = new PharmacyHead()
     193                {
     194                    Id = Phead.Id,
     195                    MedicineList = Phead.MedicineList,
     196                    PharmaciesList = Phead.PharmaciesList,
     197                    Email = Phead.Email,
     198                    Name = Phead.Name,
     199                    Password = Phead.Password
     200                };
     201                return pharHead;
     202            }
     203            else throw new Exception("Username is null.");
    102204        }
    103205    }
  • FarmatikoServices/Services/ProcessJSONService.cs

    rad60966 r1db5673  
    5858                string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx";
    5959                string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";
    60                 int count = 0;
    6160                Uri uri1 = new Uri(url1);
    6261                Uri uri2 = new Uri(url2);
  • FarmatikoServices/Services/Service.cs

    rad60966 r1db5673  
    4444        public async Task<IEnumerable<Medicine>> GetMedicines()
    4545        {
    46             var Medicines = await _repository.GetMedicines();
     46            var Medicines = await _repository.GetMedicinesAsync();
    4747            return Medicines;
    4848        }
     
    126126            else throw new Exception("Pharmacy is null");
    127127        }
     128
    128129        // Ovaa kontrola ja ima samo admin
    129130        public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
     
    131132            if (pharmacyHead != null)
    132133            {
    133                 var Medicines = await _repository.GetMedicines();
     134                var Medicines = await _repository.GetMedicinesAsync();
    134135                foreach (var med in Medicines)
    135136                {
    136                     MedicineList medicine = new MedicineList()
    137                     {
    138                         Medicine = med,
    139                         HasMedicine = false
    140                     };
    141                     pharmacyHead.MedicineLists.Add(medicine);
     137                    pharmacyHead.MedicineList.Add(med);
    142138                }
     139               
    143140                await _repository.AddPharmacyHead(pharmacyHead);
    144141            }
    145             throw new Exception("PharmacyHead is null");
     142            else throw new Exception("PharmacyHead is null");
    146143        }
    147144        //za json(Sys updater)
Note: See TracChangeset for help on using the changeset viewer.