Ignore:
Timestamp:
07/31/20 10:15:02 (4 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
d8fafb8
Parents:
4e72684
Message:

Update & add service

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoData/FarmatikoRepo/MedicineListRepository.cs

    r4e72684 ra55ef91  
    11using FarmatikoData.Models;
     2using Microsoft.EntityFrameworkCore;
    23using System.Collections.Generic;
    34using System.Linq;
     
    1718            _context.SaveChangesAsync();
    1819        }
    19         public MedicineList CheckMedicine(string Name)
     20        /*public MedicineList CheckMedicine(string Name)
    2021        {
    2122            return (MedicineList)_context.MedicineLists
    2223                .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
    23                 .OrderBy(x => x.Medicine.Name);
    24         }
    25 
    26         public IEnumerable<MedicineList> GetAll()
     24                .OrderBy(x => x.Medicine.Name)
     25                .Include(x => x.HasMedicine)
     26                .Cast<MedicineList>();
     27        }*/
     28         
     29        public IQueryable<MedicineList> GetAll()
    2730        {
    2831            return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
     
    3336            return (ICollection<MedicineList>)_context.MedicineLists
    3437                .Where(x => x.Medicine.Manufacturer.Contains(Manufacturer))
    35                 .OrderBy(x => x.Medicine.Name);
     38                .OrderBy(x => x.Medicine.Name)
     39                .Cast<ICollection<MedicineList>>();
    3640        }
    3741        public ICollection<MedicineList> GetByName(string Name)
     
    3943            return (ICollection<MedicineList>)_context.MedicineLists
    4044                .Where(x => x.Medicine.Name.Contains(Name))
    41                 .OrderBy(x => x.Medicine.Name);
     45                .OrderBy(x => x.Medicine.Name)
     46                .Cast<ICollection<MedicineList>>();
    4247        }
    4348
    4449        public void Remove(MedicineList medicineList)
    4550        {
    46             var list = (MedicineList)_context.MedicineLists.Where(x => x.Equals(medicineList));
     51            var list = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
    4752            _context.MedicineLists.Remove(list);
    48         }
    49 
    50         public bool SetHasMedicine(MedicineList medicineList, bool HasMedicine)
    51         {
    52             MedicineList medicine = (MedicineList)_context.MedicineLists.Where(x => x.Medicine.Name.Equals(medicineList.Medicine.Name));
    53            
    54             if (medicine != null || medicineList != null)
    55             {
    56                 if (HasMedicine == true)
    57                 {
    58                     medicine.HasMedicine = HasMedicine;
    59                     _context.MedicineLists.Add(medicine);
    60                     _context.SaveChangesAsync();
    61                     return true;
    62                 }
    63                 else
    64                 {
    65                     medicine.HasMedicine = HasMedicine;
    66                     _context.MedicineLists.Add(medicine);
    67                     _context.SaveChangesAsync();
    68                     return true;
    69                 }
    70             }else
    71             {
    72                 return false;
    73             }
    7453        }
    7554    }
Note: See TracChangeset for help on using the changeset viewer.