Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/Services/PHService.cs

    r8eb1e21 re0cdea2  
    8686                    if (!pharmacyHead.Medicines.Equals(PHMedicines))
    8787                    {
    88                         /*
    89                          * USELESS
    90                          * if (pharmacyHead.Medicines.Count() == 0)
     88                        //phead.Medicines = pharmacyHead.Medicines;
     89                        if (pharmacyHead.Medicines.Count() == 0)
    9190                        {
    9291                            phead.Medicines = null;
     
    9695                            _iPHRepo.DeletePHMedicine(PHMId, phId, medId);
    9796                            return;
    98                         }*/
     97                        }
    9998                        if (phead.Medicines != null && phead.Medicines.Count() > 0)
    10099                        {
     
    120119                                    Medicine = medicine
    121120                                };
    122 
     121                               
    123122                                bool ifExists = phead.Medicines.Contains(phm);
    124123                                if (!ifExists)
     
    154153                    }
    155154                }
     155
    156156                PharmacyHead head = new PharmacyHead()
    157157                {
    158158                    Name = pharmacyHead.Name,
    159159                    Email = pharmacyHead.Email,
    160                     Password = pharmacyHead.Password,
    161                     Medicines = phead.Medicines,
    162                     Pharmacies = phead.Pharmacies
     160                    Password = pharmacyHead.Password
    163161                };
    164                 if (!phead.Name.Equals(head.Name) && !phead.Password.Equals(head.Email))
     162
     163                if (pharmacyHead.Pharmacies != null)
     164                {
     165                    if (pharmacyHead.Pharmacies.Count() > 0)
     166                    {
     167                        phead.Pharmacies = pharmacyHead.Pharmacies;
     168                        head.Pharmacies = pharmacyHead.Pharmacies;
     169                    }
     170                }
     171               
     172                if (!phead.Equals(head))
    165173                {
    166174                    await _iPHRepo.UpdatePharmacyHead(head);
    167175                }
    168                 List<Pharmacy> pharmacies = new List<Pharmacy>();
    169                 pharmacies = phead.Pharmacies;
    170                 if (head.Pharmacies != null && pharmacyHead.Pharmacies != null)
    171                 {
    172                     if (head.Pharmacies.Count() > 0 && pharmacyHead.Pharmacies.Count() > 0)
    173                     {
    174                         foreach (var pharmacy in pharmacyHead.Pharmacies)
    175                         {
    176                             if (!head.Pharmacies.Contains(pharmacy))
    177                             {
    178                                 pharmacy.PheadId = phead.Id;
    179                                 pharmacy.PharmacyHead = phead;
    180                                 pharmacies.Add(pharmacy);
    181                             }
    182                         }
    183                         head.Pharmacies = pharmacies;
    184                         await _iPHRepo.UpdatePharmacyHead(head);
    185                     }
    186                 }
    187             }
    188             else throw new Exception("Cannot update pharmacy head since there was no changes.");
     176                else throw new Exception("Cannot update pharmacy head since there was no changes.");
     177            }
     178            else throw new Exception("PharmacyHead has a null value.");
    189179        }
    190180        public async Task<bool> Add(PharmacyHeadDto pharmacyHead)
Note: See TracChangeset for help on using the changeset viewer.