Ignore:
Timestamp:
07/29/20 20:02:58 (4 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
a55ef91
Parents:
de18858
Message:

Add services

File:
1 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoData/FarmatikoRepo/MedicineListRepository.cs

    rde18858 r4e72684  
    11using FarmatikoData.Models;
    2 using Microsoft.EntityFrameworkCore;
    3 using System;
    42using System.Collections.Generic;
    53using System.Linq;
    6 using System.Text;
    74
    85namespace FarmatikoData.FarmatikoRepo
     
    2017            _context.SaveChangesAsync();
    2118        }
    22         // Maybe later
    23         /*public MedicineList CheckMedicine(string Name)
     19        public MedicineList CheckMedicine(string Name)
    2420        {
    2521            return (MedicineList)_context.MedicineLists
    2622                .Where(medicineList => medicineList.Medicine.Name.Contains(Name))
    2723                .OrderBy(x => x.Medicine.Name);
    28         }*/
     24        }
    2925
    30         public ICollection<MedicineList> GetAll()
     26        public IEnumerable<MedicineList> GetAll()
    3127        {
    32             return (ICollection<MedicineList>)_context.MedicineLists.OrderBy(x => x.Medicine.Name);
     28            return _context.MedicineLists.OrderBy(x => x.Medicine.Name);
    3329        }
    3430
     
    4945        {
    5046            var list = (MedicineList)_context.MedicineLists.Where(x => x.Equals(medicineList));
    51             _context.Remove(list);
     47            _context.MedicineLists.Remove(list);
    5248        }
    5349
    54         public void SetHasMedicine(MedicineList medicineList, bool HasMedicine)
     50        public bool SetHasMedicine(MedicineList medicineList, bool HasMedicine)
    5551        {
    56             var medicine = _context.MedicineLists.Where(x => x.Medicine.Equals(medicineList.Medicine));
     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            }
    5774        }
    5875    }
Note: See TracChangeset for help on using the changeset viewer.