Ignore:
Timestamp:
11/16/20 03:55:10 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
db484c9
Parents:
8b13eb2
Message:

Fix bugs, add some more.

Location:
FarmatikoServices/Services
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/Services/PHService.cs

    r8b13eb2 r8e74e2f  
    55using System.Collections.Generic;
    66using System.Linq;
    7 using System.Text;
    87using System.Threading.Tasks;
    98
     
    6463                var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email);
    6564
    66                 if (pharmacyHead.PharmaciesList.Count() == 0)
    67                     pharmacyHead.PharmaciesList = null;
     65                /*if (pharmacyHead.PharmaciesList.Count() == 0)
     66                    pharmacyHead.PharmaciesList = null;*/
    6867
    6968
    7069                phead.PHMedicineList = _repository.GetPHMedicines(phead.Email);
    7170
    72                 if (phead.MedicineList != pharmacyHead.MedicineList || phead != pharmacyHead)
     71                if (phead.MedicineList != pharmacyHead.MedicineList)
    7372                {
    7473                    phead.MedicineList = pharmacyHead.MedicineList;
     
    8382                        return;
    8483                    }
    85                     foreach (var med in phead.MedicineList)
    86                     {
    87                         med.Id++;
    88                         var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine
     84                    List<PharmacyHeadMedicine> PHMList = new List<PharmacyHeadMedicine>();
     85                    if (phead.PHMedicineList == pharmacyHead.PHMedicineList)
     86                    {
     87                        foreach (var med in phead.MedicineList)
    8988                        {
    90                             PheadId = x.PheadId,
    91                             Head = x.Head,
    92                             MedicineId = x.MedicineId,
    93                             Medicine = x.Medicine
    94                         }).Where(x => x.MedicineId == med.Id).Single();
    95                         list.Add(PHMObj);
     89                            //list = phead.PHMedicineList.ToList();
     90
     91                            var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine
     92                            {
     93                                Id = x.Id,
     94                                PheadId = x.PheadId,
     95                                Head = x.Head,
     96                                MedicineId = x.MedicineId,
     97                                Medicine = x.Medicine
     98                            }).Where(x => x.MedicineId == med.Id).Single();
     99                            if (PHMObj == null || PHMObj == default)
     100                                break;
     101                            if (PHMObj.MedicineId == med.Id)
     102                                list.Add(PHMObj);
     103
     104                        }
     105
     106                        phead.PHMedicineList = list;
    96107                    }
    97108
    98                     phead.PHMedicineList = list;
    99 
    100109                    await _iPHRepo.UpdatePharmacyHead(phead);
     110                }
     111                else if (!phead.Equals(pharmacyHead))
     112                {
     113                    await _iPHRepo.UpdatePharmacyHead(pharmacyHead);
    101114                }
    102115                else throw new Exception("Cannot update pharmacy head since there was no changes.");
     
    154167                if (user.UserRole.ToString().Equals("Admin"))
    155168                {
    156                     var Admin = new
     169                    var Admin = new PharmacyHead()
    157170                    {
    158171                        Id = user.Id,
    159172                        Email = user.Email,
    160173                        Name = user.Name,
    161                         Passwd = user.Password,
    162                         MedicineList = PHMedicines,
     174                        Password = user.Password,
    163175                        PharmaciesList = Phead.PharmaciesList
    164176                    };
     
    167179                }
    168180
    169                 if (PheadPharms.Count() > 0)
    170                     Phead.MedicineList = PHMedicineList;
     181                if (PheadPharms.Count() > 0 || PheadPharms != null)
     182                    Phead.PharmaciesList = PheadPharms;
    171183                else Phead.PharmaciesList = pharmacies;
    172184
    173                 if (Phead.PHMedicineList.Count() > 0)
     185                if (Phead.PHMedicineList.Count() > 0 || Phead.PHMedicineList != null)
    174186                {
    175187                    foreach (var med in Medicines)
    176188                    {
    177                         var PHMObj = Phead.PHMedicineList.Select(x => new PharmacyHeadMedicine
     189
     190                        var PHMObj = Phead.PHMedicineList.Where(x => x.MedicineId == med.Id).SingleOrDefault();
     191                        if (PHMObj == null)
    178192                        {
    179                             PheadId = x.PheadId,
    180                             Head = x.Head,
    181                             MedicineId = x.MedicineId,
    182                             Medicine = x.Medicine
    183                         }).Where(x => x.MedicineId == med.Id).SingleOrDefault();
    184                         if (PHMObj == null || PHMObj == default)
    185                             break;
     193                            continue;
     194                        }
     195                        var phm = Phead.MedicineList;
    186196                        if (PHMObj.MedicineId == med.Id)
    187197                        {
    188                             Medicine medicine = new Medicine(med.Name, med.Strength, med.Form, med.WayOfIssuing, med.Manufacturer, med.Price, med.Packaging);
     198                            var medicine = new Medicine()
     199                            {
     200                                Id = med.Id,
     201                                Name = med.Name,
     202                                Strength = med.Strength,
     203                                Form = med.Form,
     204                                WayOfIssuing = med.WayOfIssuing,
     205                                Manufacturer = med.Manufacturer,
     206                                Price = med.Price,
     207                                Packaging = med.Packaging
     208                            };
    189209                            PHMedicineList.Add(medicine);
    190210                        }
  • FarmatikoServices/Services/Service.cs

    r8b13eb2 r8e74e2f  
    128128
    129129        // Ovaa kontrola ja ima samo admin
     130        public User MakeUser(PharmacyHead head)
     131        {
     132            var users = _repository.GetUsers();
     133           
     134            User user = new User()
     135            {
     136                Name = head.Name,
     137                Password = head.Password,
     138                Email = head.Email,
     139                UserRole = User.Role.PharmacyHead
     140            };
     141            return user;
     142        }
    130143        public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
    131144        {
    132145            if (pharmacyHead != null)
    133146            {
    134                 /*var Medicines = await _repository.GetMedicinesAsync();
    135                 foreach (var med in Medicines)
    136                 {
    137                     pharmacyHead.MedicineList.Add(med);
    138                 }*/
    139                
     147                var user = MakeUser(pharmacyHead);
     148                await _repository.AddUser(user);               
    140149                await _repository.AddPharmacyHead(pharmacyHead);
    141150            }
Note: See TracChangeset for help on using the changeset viewer.