Ignore:
Timestamp:
10/28/20 22:06:48 (4 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
993189e
Parents:
1454207
Message:

Change methods & add error controller

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/Services/PHService.cs

    r1454207 r6f203af  
    1818        }
    1919
    20         public async Task ClaimPharmacy(RequestPharmacyHead pharmacy)
     20        public async Task<bool> ClaimPharmacy(RequestPharmacyHead pharmacy)
    2121        {
    22             await _iPHRepo.ClaimPharmacy(pharmacy);
     22            if (pharmacy != null)
     23            {
     24                await _iPHRepo.ClaimPharmacy(pharmacy);
     25                return true;
     26            }
     27            return false;
    2328        }
    2429
    25         public Task<IQueryable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     30        public async Task<PharmacyHead> GetPharmacyHeadByIdAsync(int id)
    2631        {
    27             throw new NotImplementedException();
     32            PharmacyHead Phead = null;
     33            if (id >= 0)
     34                Phead = await _iPHRepo.GetPharmacyHeadByIdAsync(id);
     35            if (Phead != null)
     36                return Phead;
     37            throw new Exception("No data found.");
     38        }
     39
     40        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     41        {
     42            var PHeads = await _iPHRepo.GetPharmacyHeadInfo();
     43            if (PHeads != null)
     44                return PHeads;
     45            throw new Exception("No Pharmacy heads found.");
    2846        }
    2947
    3048        public async Task<int> Login(PharmacyHead pharmacyHead)
    3149        {
    32             var PHead = await Task.Run(() => _iPHRepo.GetPharmacyHead(pharmacyHead));
     50            var PHead = await _iPHRepo.GetPharmacyHeadByIdAsync(pharmacyHead.Id);
    3351            if (PHead.Password.Equals(pharmacyHead.Password))
    3452                return PHead.Id;
     
    4361            else throw new Exception("PharmacyHead has a null value.");
    4462        }
     63        public async Task<bool> Add(PharmacyHead pharmacyHead)
     64        {
     65            if (pharmacyHead != null)
     66            {
     67                await _iPHRepo.Add(pharmacyHead);
     68                return true;
     69            }
     70            return false;
     71        }
     72
     73        public async Task<bool> Remove(int id)
     74        {
     75            PharmacyHead Phead = await _iPHRepo.GetPharmacyHeadByIdAsync(id);
     76            if (Phead != null && id >= 0)
     77            {
     78                Phead.DeletedOn = DateTime.UtcNow;
     79                await _iPHRepo.Remove(Phead);
     80                return true;
     81            }
     82            return false;
     83        }
     84
     85        public async Task<bool> RemoveClaimingRequest(int id)
     86        {
     87            if (id >= 0)
     88            {
     89                await _iPHRepo.RemoveClaimingRequest(id);
     90                return true;
     91            }
     92            return false;
     93        }
    4594    }
    4695}
Note: See TracChangeset for help on using the changeset viewer.