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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.