Changeset 1db5673
- Timestamp:
- 11/14/20 12:27:30 (4 years ago)
- Branches:
- master
- Children:
- 68454c6
- Parents:
- ad60966
- Files:
-
- 2 added
- 1 deleted
- 30 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko.sln
rad60966 r1db5673 9 9 EndProject 10 10 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmatikoServices", "FarmatikoServices\FarmatikoServices.csproj", "{D207CD1B-4C31-4414-9EF4-DC18F219CBF6}" 11 EndProject 12 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F354500C-6124-4A4D-AEC2-A38CF3F436CF}" 13 ProjectSection(SolutionItems) = preProject 14 .editorconfig = .editorconfig 15 EndProjectSection 11 16 EndProject 12 17 Global -
Farmatiko/ClientApp/src/app/admin/admin.component.html
rad60966 r1db5673 76 76 <input matInput [(ngModel)]="this.head.Passwd"> 77 77 </mat-form-field><br> 78 <button onclick="createHead()" mat-raised-button color="primary">Create</button>78 <button (click)="createHead()" mat-raised-button color="primary">Create</button> 79 79 </div> 80 80 </mat-tab> -
Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts
rad60966 r1db5673 43 43 44 44 claimPharmacy(pharmacy: IPharmacy) { 45 if(pharmacy && !this.head.Pharmacy.find(x => x === pharmacy)) { 46 this.request = null; 47 this.request.Pharmacy = pharmacy; 48 this.request.PharmacyHead = this.head; 49 this.dataService.claimPharmacy(this.request) 50 .subscribe((req: IPharmacyHeadRequest) => { 51 if(req) { 52 this.openSnackBar("Claiming request sent!", "OK"); 53 } 54 else { 55 this.openSnackBar("Unable to send a request", "Try again"); 56 } 57 }, 58 (err: any) => console.log(err), 59 () => console.log('Claiming request sent!')); 45 if(this.head.Pharmacy != null) { 46 if(pharmacy && !this.head.Pharmacy.find(x => x === pharmacy)) { 47 this.request = {}; 48 this.request.Pharmacy = pharmacy; 49 this.request.PharmacyHead = this.head; 50 this.dataService.claimPharmacy(this.request) 51 .subscribe((req) => { 52 if(req) { 53 this.openSnackBar("Claiming request sent!", "OK"); 54 } 55 else { 56 this.openSnackBar("Unable to send a request", "Try again"); 57 } 58 }, 59 (err: any) => console.log(err), 60 () => console.log('Claiming request sent!')); 61 } 62 } 63 else { 64 if(pharmacy) { 65 this.request = {}; 66 this.request.Pharmacy = pharmacy; 67 this.request.PharmacyHead = this.head; 68 this.dataService.claimPharmacy(this.request) 69 .subscribe((req) => { 70 if(req) { 71 this.openSnackBar("Claiming request sent!", "OK"); 72 } 73 else { 74 this.openSnackBar("Unable to send a request", "Try again"); 75 } 76 }, 77 (err: any) => console.log(err), 78 () => console.log('Claiming request sent!')); 79 } 60 80 } 61 81 } -
Farmatiko/ClientApp/src/app/login/login.component.ts
rad60966 r1db5673 54 54 .subscribe( 55 55 (data) => { 56 if(data.role == 'Admin') {56 if(data.role === 'Admin') { 57 57 this.router.navigate(['/admin']); 58 58 } -
Farmatiko/ClientApp/src/app/shared/data.service.ts
rad60966 r1db5673 6 6 7 7 import { IHealthFacilities, IHealthcareWorkers, IMedicine, IPandemic, IPharmacy, IPharmacyHead, IPharmacyHeadRequest } from './interfaces'; 8 import { environment } from '../../environments/environment'; 8 9 9 10 @Injectable() 10 11 export class DataService { 11 baseFacilitiesUrl: string = '/api/facilities';12 baseWorkersUrl: string = '/api/workers';13 baseMedicineUrl: string = '/api/medicines';14 basePandemicUrl: string = '/api/pandemic';15 basePharmacyUrl: string = '/api/pharmacy';16 basePharmacyHead: string = '/api/pharmacyhead';12 baseFacilitiesUrl: string = `${environment.baseApiUrl}api/facilities`; 13 baseWorkersUrl: string = `${environment.baseApiUrl}api/workers`; 14 baseMedicineUrl: string = `${environment.baseApiUrl}api/medicines`; 15 basePandemicUrl: string = `${environment.baseApiUrl}api/pandemic`; 16 basePharmacyUrl: string = `${environment.baseApiUrl}api/pharmacy`; 17 basePharmacyHead: string = `${environment.baseApiUrl}api/pharmacyhead`; 17 18 18 19 constructor(private http: HttpClient) { … … 179 180 //PharmacyHead PUT 180 181 updatePharmacyHead(head: IPharmacyHead) : Observable<IPharmacyHead> { 181 return this.http.put<IPharmacyHead>(this.basePharmacyHead + '/' + head.id, head)182 return this.http.put<IPharmacyHead>(this.basePharmacyHead, head) 182 183 .pipe( 183 184 map((data) => { -
Farmatiko/ClientApp/src/app/shared/interfaces.ts
rad60966 r1db5673 57 57 originalUserName?: string; 58 58 Role?: string; 59 } 60 59 } 61 60 export interface IPharmacyHeadRequest { 62 61 id?: string; -
Farmatiko/ClientApp/src/app/shared/services/auth.service.ts
rad60966 r1db5673 9 9 10 10 interface LoginResult { 11 user name: string;11 userName: string; 12 12 role: string; 13 13 originalUserName?: string; … … 36 36 this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => { 37 37 this._user.next({ 38 Email: x.user name,38 Email: x.userName, 39 39 Passwd: x.head.Passwd, 40 40 Role: x.role, … … 64 64 map((x) => { 65 65 this._user.next({ 66 Email: x.user name,66 Email: x.userName, 67 67 Passwd: x.head.Passwd, 68 68 Role: x.role, … … 105 105 map((x) => { 106 106 this._user.next({ 107 Email: x.user name,107 Email: x.userName, 108 108 Passwd: x.head.Passwd, 109 109 Role: x.role, -
Farmatiko/ClientApp/tsconfig.json
rad60966 r1db5673 2 2 "compileOnSave": false, 3 3 "compilerOptions": { 4 "baseUrl": "https://localhost: 44342/",4 "baseUrl": "https://localhost:5001/", 5 5 "module": "esnext", 6 6 "outDir": "./dist/out-tsc", -
Farmatiko/Controllers/AdminController.cs
rad60966 r1db5673 11 11 { 12 12 [ApiController] 13 [Authorize(Roles = " PharmacyHead")]13 [Authorize(Roles = "Admin")] 14 14 public class AdminController : Controller 15 15 { -
Farmatiko/Controllers/FarmatikoController.cs
rad60966 r1db5673 27 27 //_JSONservice.GetProcessedHealthFacilitiesFromJSON(); 28 28 //_JSONservice.GetProcessedMedicinesFromJSON(); 29 //_JSONservice.GetProcessedPandemicsFromJSONApi();29 _JSONservice.GetProcessedPandemicsFromJSONApi(); 30 30 } 31 31 [HttpGet] -
Farmatiko/Controllers/LoginController.cs
rad60966 r1db5673 61 61 Role = role, 62 62 AccessToken = jwtResult.AccessToken, 63 RefreshToken = jwtResult.RefreshToken.TokenString, 63 RefreshToken = jwtResult.RefreshToken.TokenString, 64 64 Head = _pHService.GetPharmacyHead(request.UserName) 65 65 }); … … 110 110 return Ok(new LoginResult 111 111 { 112 /*UserName = userName, 113 114 Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty, 115 AccessToken = jwtResult.AccessToken, 116 RefreshToken = jwtResult.RefreshToken.TokenString*/ 117 112 118 UserName = userName, 113 119 Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty, 114 120 AccessToken = jwtResult.AccessToken, 115 RefreshToken = jwtResult.RefreshToken.TokenString 121 RefreshToken = jwtResult.RefreshToken.TokenString, 122 Head = _pHService.GetPharmacyHead(userName) 116 123 }); 117 124 } … … 156 163 OriginalUserName = userName, 157 164 AccessToken = jwtResult.AccessToken, 158 RefreshToken = jwtResult.RefreshToken.TokenString 165 RefreshToken = jwtResult.RefreshToken.TokenString, 166 Head = _pHService.GetPharmacyHead(userName) 159 167 }); 160 168 } … … 186 194 OriginalUserName = null, 187 195 AccessToken = jwtResult.AccessToken, 188 RefreshToken = jwtResult.RefreshToken.TokenString 196 RefreshToken = jwtResult.RefreshToken.TokenString, 197 Head = _pHService.GetPharmacyHead(userName) 189 198 }); 190 199 } … … 204 213 public class LoginResult 205 214 { 206 [JsonPropertyName("user name")]215 [JsonPropertyName("userName")] 207 216 public string UserName { get; set; } 208 217 … … 219 228 public string RefreshToken { get; set; } 220 229 [JsonPropertyName("head")] 221 public PharmacyHeadHead { get; set; }230 public object Head { get; set; } 222 231 } 223 232 … … 230 239 public class ImpersonationRequest 231 240 { 232 [JsonPropertyName("user name")]241 [JsonPropertyName("userName")] 233 242 public string UserName { get; set; } 234 243 } -
Farmatiko/Controllers/PharmacyHeadController.cs
rad60966 r1db5673 19 19 20 20 //GET 21 /*[HttpGet] 21 /* 22 [HttpGet] 22 23 [Route("api/pharmacyhead")] 23 24 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() … … 26 27 return PHeads; 27 28 }*/ 29 28 30 [HttpGet] 29 31 [Route("api/pharmacyhead/{Id}")] … … 34 36 } 35 37 //POST 38 /* 36 39 [HttpPost] 37 40 [Route("api/pharmacyhead/add")] … … 40 43 bool Success = await _PHService.Add(pharmacyHead); 41 44 return Ok(Success); 42 } 45 }*/ 43 46 44 47 /*[HttpPost] … … 49 52 }*/ 50 53 [HttpPut] 51 [Route("api/pharmacyhead/{Id}")] 54 [Route("api/pharmacyhead")] 55 [Authorize(Roles = "Admin")] 56 [Authorize(Roles = "PharmacyHead")] 52 57 public async Task UpdatePharmacyHead([FromBody]PharmacyHead pharmacyHead) 53 58 { -
Farmatiko/Farmatiko.csproj
rad60966 r1db5673 15 15 <ItemGroup> 16 16 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" /> 17 <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.10" /> 18 <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.10" /> 17 19 <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.6" /> 18 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1. 6" />19 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1. 6">20 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" /> 21 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10"> 20 22 <PrivateAssets>all</PrivateAssets> 21 23 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 22 24 </PackageReference> 23 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1. 6">25 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10"> 24 26 <PrivateAssets>all</PrivateAssets> 25 27 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 26 28 </PackageReference> 29 <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> 27 30 <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" /> 28 31 </ItemGroup> … … 38 41 <Compile Remove="Controllers\WeatherForecastController.cs" /> 39 42 <Compile Remove="WeatherForecast.cs" /> 43 </ItemGroup> 44 45 <ItemGroup> 46 <None Include="..\.editorconfig" Link=".editorconfig" /> 40 47 </ItemGroup> 41 48 -
Farmatiko/Startup.cs
rad60966 r1db5673 18 18 using FarmatikoServices.Infrastructure; 19 19 using System; 20 20 using Newtonsoft.Json.Serialization; 21 21 namespace Farmatiko 22 22 { … … 45 45 46 46 services.AddControllersWithViews(); 47 services.AddControllersWithViews().AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); 47 48 // In production, the Angular files will be served from this directory 48 49 services.AddSpaStaticFiles(configuration => … … 53 54 services.AddEntityFrameworkNpgsql().AddDbContext<FarmatikoDataContext>(opt => opt.UseNpgsql(connectionString)); 54 55 55 services.Add Transient<IPHRepo, PHRepo>();56 services.AddScoped<IPHRepo, PHRepo>(); 56 57 services.AddTransient<IRepository, Repository>(); 57 58 services.AddTransient<IAdminRepo, AdminRepo>(); -
FarmatikoData/Base/BaseEntity.cs
rad60966 r1db5673 3 3 using System.Text; 4 4 using System.ComponentModel.DataAnnotations; 5 using System.Text.Json.Serialization; 5 6 6 7 namespace FarmatikoData.Base … … 8 9 public class BaseEntity 9 10 { 10 public int Id { get; set; } 11 [JsonPropertyName("id")] 12 public int Id { get; set; } 11 13 public DateTime CreatedOn { get; set; } 12 14 public DateTime? DeletedOn { get; set; } -
FarmatikoData/FarmatikoData.csproj
rad60966 r1db5673 6 6 7 7 <ItemGroup> 8 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6"> 8 <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.10" /> 9 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" /> 10 <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10"> 9 11 <PrivateAssets>all</PrivateAssets> 10 12 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 11 13 </PackageReference> 12 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1. 6">14 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.10"> 13 15 <PrivateAssets>all</PrivateAssets> 14 16 <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> -
FarmatikoData/FarmatikoDataContext.cs
rad60966 r1db5673 15 15 public virtual DbSet<Pandemic> Pandemics { get; set; } 16 16 public virtual DbSet<Medicine> Medicines { get; set; } 17 //public virtual DbSet<MedicineList> MedicineLists { get; set; }18 17 public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; } 19 18 public virtual DbSet<User> Users { get; set; } 19 public virtual DbSet<PharmacyHeadMedicine> PharmacyHeadMedicines { get; set; } 20 21 protected override void OnModelCreating(ModelBuilder modelBuilder) 22 { 23 modelBuilder.Entity<PharmacyHead>() 24 .ToTable("PharmacyHeads"); 25 26 modelBuilder.Entity<Medicine>() 27 .ToTable("Medicines"); 28 29 modelBuilder.Entity<PharmacyHeadMedicine>() 30 .HasKey(phm => new { phm.PheadId, phm.MedicineId }); 31 modelBuilder.Entity<PharmacyHeadMedicine>() 32 .HasOne(ph => ph.Head) 33 .WithMany(m => m.PHMedicineList) 34 .HasForeignKey(k => k.PheadId); 35 36 modelBuilder.Entity<PharmacyHeadMedicine>() 37 .HasOne(m => m.Medicine) 38 .WithMany(ml => ml.MedicineList) 39 .HasForeignKey(k => k.MedicineId); 40 41 modelBuilder.Entity<PharmacyHead>() 42 .HasMany(p => p.PharmaciesList) 43 .WithOne(h => h.PHead) 44 .HasForeignKey(k => k.PheadId); 45 46 base.OnModelCreating(modelBuilder); 47 } 20 48 } 21 49 } -
FarmatikoData/FarmatikoRepo/PHRepo.cs
rad60966 r1db5673 31 31 Email = x.Email, 32 32 Password = x.Password, 33 MedicineList s = x.MedicineLists,33 MedicineList = x.MedicineList, 34 34 PharmaciesList = x.PharmaciesList 35 35 }).ToListAsync(); … … 39 39 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead) 40 40 { 41 var EditedPHead = await _context.PharmacyHeads.Where(x => x.Id == pharmacyHead.Id).FirstOrDefaultAsync(); 41 var Phead = await _context.PharmacyHeads.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 42 var EditedPHead = await _context.PharmacyHeads.AsNoTracking<PharmacyHead>().Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 42 43 EditedPHead.Email = pharmacyHead.Email; 43 44 EditedPHead.Name = pharmacyHead.Name; 44 45 EditedPHead.Password = pharmacyHead.Password; 45 EditedPHead.MedicineLists = pharmacyHead.MedicineLists; 46 /*if (pharmacyHead.MedicineList.Count() == 0) 47 pharmacyHead.MedicineList = null;*/ 48 EditedPHead.MedicineList = pharmacyHead.MedicineList; 46 49 EditedPHead.PharmaciesList = pharmacyHead.PharmaciesList; 50 EditedPHead.PHMedicineList = pharmacyHead.PHMedicineList; 51 //_context.Entry<PharmacyHead>(Phead).State = EntityState.Detached; 52 Phead = EditedPHead; 47 53 await _context.SaveChangesAsync(); 48 54 } … … 72 78 } 73 79 80 74 81 public PharmacyHead GetPharmacyHeadByUserName(string userName) 75 82 { 76 return_context.PharmacyHeads83 var PHead = _context.PharmacyHeads 77 84 .Where(x => x.Email.Equals(userName)) 78 85 .FirstOrDefault(); 86 87 return PHead; 88 } 89 90 public List<PharmacyHeadMedicine> GetPharmacyHeadMedicines(string email) 91 { 92 /*var meds = _context.Medicines.ToList(); 93 var medicines = Medicines;*/ 94 var Phead = _context.PharmacyHeads.Where(x => x.Email.Equals(email)).FirstOrDefault(); 95 var Medicines = _context.PharmacyHeadMedicines.Where(x => x.PheadId == Phead.Id).ToList(); 96 /*.Select(x => x.Head.MedicineList) 97 .SelectMany(mList => mList) 98 .ToList();*/ 99 100 101 return Medicines; 102 } 103 104 public IEnumerable<PharmacyHead> GetPharmacyHeads() 105 { 106 var heads = _context.PharmacyHeads.ToList(); 107 return heads; 108 } 109 110 public PharmacyHead GetPharmacyHead(string head) 111 { 112 var phead = _context.PharmacyHeads.Where(x => x.Email.Equals(head)).FirstOrDefault(); 113 return phead; 114 } 115 116 public List<Pharmacy> GetPharmacies() 117 { 118 var pharms = _context.Pharmacies.ToList(); 119 return pharms; 79 120 } 80 121 } -
FarmatikoData/FarmatikoRepo/Repository.cs
rad60966 r1db5673 41 41 } 42 42 43 public async Task<IEnumerable<Medicine>> GetMedicines() 44 { 45 var Medicines = await _context.Medicines.Take(3).ToListAsync(); 43 public async Task<IEnumerable<Medicine>> GetMedicinesAsync() 44 { 45 var Medicines = await _context.Medicines.Select(x => new Medicine 46 { 47 Name = x.Name, 48 Strength = x.Strength, 49 Form = x.Form, 50 WayOfIssuing = x.WayOfIssuing, 51 Manufacturer = x.Manufacturer, 52 Price = x.Price, 53 Packaging = x.Packaging 54 55 }).Take(3).ToListAsync(); 46 56 return Medicines; 47 57 } … … 205 215 public Task UpdateMedicine(Medicine medicine) 206 216 { 207 throw new System.NotImplementedException();217 throw new NotImplementedException(); 208 218 } 209 219 … … 227 237 return users; 228 238 } 239 240 public User GetRole(string userName) 241 { 242 var user = _context.Users.Where(x => x.Email.Equals(userName)).FirstOrDefault(); 243 return user; 244 } 245 246 public ICollection<Medicine> GetMedicines() 247 { 248 var Medicines = _context.Medicines.Select(x => new Medicine 249 { 250 Id = x.Id, 251 Name = x.Name, 252 Strength = x.Strength, 253 Form = x.Form, 254 WayOfIssuing = x.WayOfIssuing, 255 Manufacturer = x.Manufacturer, 256 Price = x.Price, 257 Packaging = x.Packaging, 258 MedicineList = x.MedicineList 259 260 }).ToList(); 261 return Medicines; 262 } 263 264 public ICollection<PharmacyHeadMedicine> GetPHMedicines(string email) 265 { 266 var head = _context.PharmacyHeads.Where(x => x.Email.Equals(email)).FirstOrDefault(); 267 var phmeds = _context.PharmacyHeadMedicines.Where(x => x.PheadId == head.Id).ToList(); 268 return phmeds; 269 } 229 270 } 230 271 } -
FarmatikoData/FarmatikoRepoInterfaces/IPHRepo.cs
rad60966 r1db5673 18 18 Task RemoveClaimingRequest(int id); 19 19 PharmacyHead GetPharmacyHeadByUserName(string userName); 20 List<PharmacyHeadMedicine> GetPharmacyHeadMedicines(string email); 21 IEnumerable<PharmacyHead> GetPharmacyHeads(); 22 PharmacyHead GetPharmacyHead(string head); 23 List<Pharmacy> GetPharmacies(); 20 24 } 21 25 } -
FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs
rad60966 r1db5673 15 15 Task<HealthFacility> GetFacility(int Id); 16 16 Task<Medicine> GetMedicine(int Id); 17 Task<IEnumerable<Medicine>> GetMedicines(); 17 Task<IEnumerable<Medicine>> GetMedicinesAsync(); 18 ICollection<Medicine> GetMedicines(); 18 19 Task<Pandemic> GetPandemic(); 19 20 Task<IEnumerable<Pharmacy>> GetPharmacies(); … … 42 43 Task UpdateMedicine(Medicine medicine); 43 44 Task RemovePharmacyHead(int Id); 45 User GetRole(string userName); 46 ICollection<PharmacyHeadMedicine> GetPHMedicines(string email); 44 47 } 45 48 } -
FarmatikoData/Migrations/20201111183247_InitialMigration.Designer.cs
rad60966 r1db5673 11 11 { 12 12 [DbContext(typeof(FarmatikoDataContext))] 13 [Migration("202011 05063549_InitialMigration")]13 [Migration("20201111183247_InitialMigration")] 14 14 partial class InitialMigration 15 15 { … … 123 123 .HasColumnType("text"); 124 124 125 b.Property<int?>("PharmacyHeadId") 126 .HasColumnType("integer"); 127 125 128 b.Property<float>("Price") 126 129 .HasColumnType("real"); … … 136 139 b.HasKey("Id"); 137 140 141 b.HasIndex("PharmacyHeadId"); 142 138 143 b.ToTable("Medicines"); 139 });140 141 modelBuilder.Entity("FarmatikoData.Models.MedicineList", b =>142 {143 b.Property<int>("Id")144 .ValueGeneratedOnAdd()145 .HasColumnType("integer")146 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);147 148 b.Property<DateTime>("CreatedOn")149 .HasColumnType("timestamp without time zone");150 151 b.Property<DateTime?>("DeletedOn")152 .HasColumnType("timestamp without time zone");153 154 b.Property<bool>("HasMedicine")155 .HasColumnType("boolean");156 157 b.Property<int>("MedicineId")158 .HasColumnType("integer");159 160 b.Property<int?>("PharmacyHeadId")161 .HasColumnType("integer");162 163 b.HasKey("Id");164 165 b.HasIndex("MedicineId");166 167 b.HasIndex("PharmacyHeadId");168 169 b.ToTable("MedicineList");170 144 }); 171 145 … … 238 212 .HasColumnType("text"); 239 213 240 b.Property<int ?>("PharmacyHeadId")214 b.Property<int>("PheadId") 241 215 .HasColumnType("integer"); 242 216 … … 246 220 b.HasKey("Id"); 247 221 248 b.HasIndex("Ph armacyHeadId");222 b.HasIndex("PheadId"); 249 223 250 224 b.ToTable("Pharmacies"); … … 279 253 280 254 b.ToTable("PharmacyHeads"); 255 }); 256 257 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 258 { 259 b.Property<int>("PheadId") 260 .HasColumnType("integer"); 261 262 b.Property<int>("MedicineId") 263 .HasColumnType("integer"); 264 265 b.Property<DateTime>("CreatedOn") 266 .HasColumnType("timestamp without time zone"); 267 268 b.Property<DateTime?>("DeletedOn") 269 .HasColumnType("timestamp without time zone"); 270 271 b.Property<int>("Id") 272 .HasColumnType("integer"); 273 274 b.HasKey("PheadId", "MedicineId"); 275 276 b.HasIndex("MedicineId"); 277 278 b.ToTable("PharmacyHeadMedicines"); 281 279 }); 282 280 … … 348 346 }); 349 347 350 modelBuilder.Entity("FarmatikoData.Models.MedicineList", b => 348 modelBuilder.Entity("FarmatikoData.Models.Medicine", b => 349 { 350 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 351 .WithMany("MedicineList") 352 .HasForeignKey("PharmacyHeadId"); 353 }); 354 355 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 356 { 357 b.HasOne("FarmatikoData.Models.PharmacyHead", "PHead") 358 .WithMany("PharmaciesList") 359 .HasForeignKey("PheadId") 360 .OnDelete(DeleteBehavior.Cascade) 361 .IsRequired(); 362 }); 363 364 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 351 365 { 352 366 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 353 .WithMany( )367 .WithMany("MedicineList") 354 368 .HasForeignKey("MedicineId") 355 369 .OnDelete(DeleteBehavior.Cascade) 356 370 .IsRequired(); 357 371 358 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 359 .WithMany("MedicineLists") 360 .HasForeignKey("PharmacyHeadId"); 361 }); 362 363 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 364 { 365 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 366 .WithMany("PharmaciesList") 367 .HasForeignKey("PharmacyHeadId"); 372 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 373 .WithMany("PHMedicineList") 374 .HasForeignKey("PheadId") 375 .OnDelete(DeleteBehavior.Cascade) 376 .IsRequired(); 368 377 }); 369 378 -
FarmatikoData/Migrations/20201111183247_InitialMigration.cs
rad60966 r1db5673 15 15 Id = table.Column<int>(nullable: false) 16 16 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 17 CreatedOn = table.Column<DateTime>(nullable: false ),17 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 18 18 DeletedOn = table.Column<DateTime>(nullable: true), 19 19 Name = table.Column<string>(nullable: false), … … 30 30 31 31 migrationBuilder.CreateTable( 32 name: "Medicines",33 columns: table => new34 {35 Id = table.Column<int>(nullable: false)36 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),37 CreatedOn = table.Column<DateTime>(nullable: false),38 DeletedOn = table.Column<DateTime>(nullable: true),39 Name = table.Column<string>(nullable: false),40 Strength = table.Column<string>(nullable: false),41 Form = table.Column<string>(nullable: true),42 WayOfIssuing = table.Column<string>(nullable: false),43 Manufacturer = table.Column<string>(nullable: false),44 Price = table.Column<float>(nullable: false),45 Packaging = table.Column<string>(nullable: true)46 },47 constraints: table =>48 {49 table.PrimaryKey("PK_Medicines", x => x.Id);50 });51 52 migrationBuilder.CreateTable(53 32 name: "Pandemics", 54 33 columns: table => new … … 56 35 Id = table.Column<int>(nullable: false) 57 36 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 58 CreatedOn = table.Column<DateTime>(nullable: false ),37 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 59 38 DeletedOn = table.Column<DateTime>(nullable: true), 60 39 Name = table.Column<string>(nullable: false), … … 78 57 Id = table.Column<int>(nullable: false) 79 58 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 80 CreatedOn = table.Column<DateTime>(nullable: false ),59 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 81 60 DeletedOn = table.Column<DateTime>(nullable: true), 82 61 Email = table.Column<string>(nullable: false), … … 95 74 Id = table.Column<int>(nullable: false) 96 75 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 97 CreatedOn = table.Column<DateTime>(nullable: false ),98 DeletedOn = table.Column<DateTime>(nullable: true), 99 Name = table.Column<string>(nullable: true),100 Email = table.Column<string>(nullable: true),101 Password = table.Column<string>(nullable: true),76 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 77 DeletedOn = table.Column<DateTime>(nullable: true), 78 Name = table.Column<string>(nullable: false), 79 Email = table.Column<string>(nullable: false), 80 Password = table.Column<string>(nullable: false), 102 81 UserRole = table.Column<int>(nullable: false) 103 82 }, … … 113 92 Id = table.Column<int>(nullable: false) 114 93 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 115 CreatedOn = table.Column<DateTime>(nullable: false ),94 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 116 95 DeletedOn = table.Column<DateTime>(nullable: true), 117 96 Name = table.Column<string>(nullable: false), … … 132 111 133 112 migrationBuilder.CreateTable( 134 name: "MedicineList", 135 columns: table => new 136 { 137 Id = table.Column<int>(nullable: false) 138 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 139 CreatedOn = table.Column<DateTime>(nullable: false), 140 DeletedOn = table.Column<DateTime>(nullable: true), 141 MedicineId = table.Column<int>(nullable: false), 142 HasMedicine = table.Column<bool>(nullable: false), 113 name: "Medicines", 114 columns: table => new 115 { 116 Id = table.Column<int>(nullable: false) 117 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 118 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 119 DeletedOn = table.Column<DateTime>(nullable: true), 120 Name = table.Column<string>(nullable: false), 121 Strength = table.Column<string>(nullable: false), 122 Form = table.Column<string>(nullable: true), 123 WayOfIssuing = table.Column<string>(nullable: false), 124 Manufacturer = table.Column<string>(nullable: false), 125 Price = table.Column<float>(nullable: false), 126 Packaging = table.Column<string>(nullable: true), 143 127 PharmacyHeadId = table.Column<int>(nullable: true) 144 128 }, 145 129 constraints: table => 146 130 { 147 table.PrimaryKey("PK_MedicineList", x => x.Id); 148 table.ForeignKey( 149 name: "FK_MedicineList_Medicines_MedicineId", 150 column: x => x.MedicineId, 151 principalTable: "Medicines", 152 principalColumn: "Id", 153 onDelete: ReferentialAction.Cascade); 154 table.ForeignKey( 155 name: "FK_MedicineList_PharmacyHeads_PharmacyHeadId", 131 table.PrimaryKey("PK_Medicines", x => x.Id); 132 table.ForeignKey( 133 name: "FK_Medicines_PharmacyHeads_PharmacyHeadId", 156 134 column: x => x.PharmacyHeadId, 157 135 principalTable: "PharmacyHeads", … … 172 150 Address = table.Column<string>(nullable: false), 173 151 WorkAllTime = table.Column<bool>(nullable: false), 174 Ph armacyHeadId = table.Column<int>(nullable: true)152 PheadId = table.Column<int>(nullable: false) 175 153 }, 176 154 constraints: table => … … 178 156 table.PrimaryKey("PK_Pharmacies", x => x.Id); 179 157 table.ForeignKey( 180 name: "FK_Pharmacies_PharmacyHeads_PharmacyHeadId", 181 column: x => x.PharmacyHeadId, 182 principalTable: "PharmacyHeads", 183 principalColumn: "Id", 184 onDelete: ReferentialAction.Restrict); 158 name: "FK_Pharmacies_PharmacyHeads_PheadId", 159 column: x => x.PheadId, 160 principalTable: "PharmacyHeads", 161 principalColumn: "Id", 162 onDelete: ReferentialAction.Cascade); 163 }); 164 165 migrationBuilder.CreateTable( 166 name: "PharmacyHeadMedicines", 167 columns: table => new 168 { 169 PheadId = table.Column<int>(nullable: false), 170 MedicineId = table.Column<int>(nullable: false), 171 Id = table.Column<int>(nullable: false), 172 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 173 DeletedOn = table.Column<DateTime>(nullable: true) 174 }, 175 constraints: table => 176 { 177 table.PrimaryKey("PK_PharmacyHeadMedicines", x => new { x.PheadId, x.MedicineId }); 178 table.ForeignKey( 179 name: "FK_PharmacyHeadMedicines_Medicines_MedicineId", 180 column: x => x.MedicineId, 181 principalTable: "Medicines", 182 principalColumn: "Id", 183 onDelete: ReferentialAction.Cascade); 184 table.ForeignKey( 185 name: "FK_PharmacyHeadMedicines_PharmacyHeads_PheadId", 186 column: x => x.PheadId, 187 principalTable: "PharmacyHeads", 188 principalColumn: "Id", 189 onDelete: ReferentialAction.Cascade); 185 190 }); 186 191 … … 191 196 Id = table.Column<int>(nullable: false) 192 197 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 193 CreatedOn = table.Column<DateTime>(nullable: false ),198 CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"), 194 199 DeletedOn = table.Column<DateTime>(nullable: true), 195 200 HeadId = table.Column<int>(nullable: false), … … 219 224 220 225 migrationBuilder.CreateIndex( 221 name: "IX_MedicineList_MedicineId", 222 table: "MedicineList", 226 name: "IX_Medicines_PharmacyHeadId", 227 table: "Medicines", 228 column: "PharmacyHeadId"); 229 230 migrationBuilder.CreateIndex( 231 name: "IX_Pharmacies_PheadId", 232 table: "Pharmacies", 233 column: "PheadId"); 234 235 migrationBuilder.CreateIndex( 236 name: "IX_PharmacyHeadMedicines_MedicineId", 237 table: "PharmacyHeadMedicines", 223 238 column: "MedicineId"); 224 225 migrationBuilder.CreateIndex(226 name: "IX_MedicineList_PharmacyHeadId",227 table: "MedicineList",228 column: "PharmacyHeadId");229 230 migrationBuilder.CreateIndex(231 name: "IX_Pharmacies_PharmacyHeadId",232 table: "Pharmacies",233 column: "PharmacyHeadId");234 239 235 240 migrationBuilder.CreateIndex( … … 250 255 251 256 migrationBuilder.DropTable( 252 name: "MedicineList");253 254 migrationBuilder.DropTable(255 257 name: "Pandemics"); 258 259 migrationBuilder.DropTable( 260 name: "PharmacyHeadMedicines"); 256 261 257 262 migrationBuilder.DropTable( -
FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs
rad60966 r1db5673 121 121 .HasColumnType("text"); 122 122 123 b.Property<int?>("PharmacyHeadId") 124 .HasColumnType("integer"); 125 123 126 b.Property<float>("Price") 124 127 .HasColumnType("real"); … … 134 137 b.HasKey("Id"); 135 138 139 b.HasIndex("PharmacyHeadId"); 140 136 141 b.ToTable("Medicines"); 137 });138 139 modelBuilder.Entity("FarmatikoData.Models.MedicineList", b =>140 {141 b.Property<int>("Id")142 .ValueGeneratedOnAdd()143 .HasColumnType("integer")144 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);145 146 b.Property<DateTime>("CreatedOn")147 .HasColumnType("timestamp without time zone");148 149 b.Property<DateTime?>("DeletedOn")150 .HasColumnType("timestamp without time zone");151 152 b.Property<bool>("HasMedicine")153 .HasColumnType("boolean");154 155 b.Property<int>("MedicineId")156 .HasColumnType("integer");157 158 b.Property<int?>("PharmacyHeadId")159 .HasColumnType("integer");160 161 b.HasKey("Id");162 163 b.HasIndex("MedicineId");164 165 b.HasIndex("PharmacyHeadId");166 167 b.ToTable("MedicineList");168 142 }); 169 143 … … 236 210 .HasColumnType("text"); 237 211 238 b.Property<int ?>("PharmacyHeadId")212 b.Property<int>("PheadId") 239 213 .HasColumnType("integer"); 240 214 … … 244 218 b.HasKey("Id"); 245 219 246 b.HasIndex("Ph armacyHeadId");220 b.HasIndex("PheadId"); 247 221 248 222 b.ToTable("Pharmacies"); … … 277 251 278 252 b.ToTable("PharmacyHeads"); 253 }); 254 255 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 256 { 257 b.Property<int>("PheadId") 258 .HasColumnType("integer"); 259 260 b.Property<int>("MedicineId") 261 .HasColumnType("integer"); 262 263 b.Property<DateTime>("CreatedOn") 264 .HasColumnType("timestamp without time zone"); 265 266 b.Property<DateTime?>("DeletedOn") 267 .HasColumnType("timestamp without time zone"); 268 269 b.Property<int>("Id") 270 .HasColumnType("integer"); 271 272 b.HasKey("PheadId", "MedicineId"); 273 274 b.HasIndex("MedicineId"); 275 276 b.ToTable("PharmacyHeadMedicines"); 279 277 }); 280 278 … … 346 344 }); 347 345 348 modelBuilder.Entity("FarmatikoData.Models.MedicineList", b => 346 modelBuilder.Entity("FarmatikoData.Models.Medicine", b => 347 { 348 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 349 .WithMany("MedicineList") 350 .HasForeignKey("PharmacyHeadId"); 351 }); 352 353 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 354 { 355 b.HasOne("FarmatikoData.Models.PharmacyHead", "PHead") 356 .WithMany("PharmaciesList") 357 .HasForeignKey("PheadId") 358 .OnDelete(DeleteBehavior.Cascade) 359 .IsRequired(); 360 }); 361 362 modelBuilder.Entity("FarmatikoData.Models.PharmacyHeadMedicine", b => 349 363 { 350 364 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 351 .WithMany( )365 .WithMany("MedicineList") 352 366 .HasForeignKey("MedicineId") 353 367 .OnDelete(DeleteBehavior.Cascade) 354 368 .IsRequired(); 355 369 356 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 357 .WithMany("MedicineLists") 358 .HasForeignKey("PharmacyHeadId"); 359 }); 360 361 modelBuilder.Entity("FarmatikoData.Models.Pharmacy", b => 362 { 363 b.HasOne("FarmatikoData.Models.PharmacyHead", null) 364 .WithMany("PharmaciesList") 365 .HasForeignKey("PharmacyHeadId"); 370 b.HasOne("FarmatikoData.Models.PharmacyHead", "Head") 371 .WithMany("PHMedicineList") 372 .HasForeignKey("PheadId") 373 .OnDelete(DeleteBehavior.Cascade) 374 .IsRequired(); 366 375 }); 367 376 -
FarmatikoData/Models/Medicine.cs
rad60966 r1db5673 1 1 using FarmatikoData.Base; 2 using System.Collections; 3 using System.Collections.Generic; 2 4 using System.ComponentModel.DataAnnotations; 5 using System.Diagnostics.CodeAnalysis; 6 using System.Text.Json.Serialization; 3 7 4 8 namespace FarmatikoData.Models … … 18 22 public float Price { get; set; } 19 23 public string Packaging { get; set; } 24 //[JsonPropertyName("PHMedicineList")] 25 public ICollection<PharmacyHeadMedicine> MedicineList { get; set; } 20 26 public Medicine(string Name, string Strength, string Form, string WayOfIssuing, string Manufacturer, float Price, string Packaging) 21 27 { … … 28 34 this.Packaging = Packaging; 29 35 } 30 31 36 } 32 37 } -
FarmatikoData/Models/Pharmacy.cs
rad60966 r1db5673 26 26 this.WorkAllTime = WorkAllTime; 27 27 } 28 public int PheadId { get; set; } 29 public PharmacyHead PHead { get; set; } 28 30 } 29 31 } -
FarmatikoData/Models/PharmacyHead.cs
rad60966 r1db5673 1 1 using System.Collections.Generic; 2 2 using System.ComponentModel.DataAnnotations; 3 using System.Text.Json.Serialization; 3 4 using FarmatikoData.Base; 5 using Newtonsoft.Json; 4 6 5 7 namespace FarmatikoData.Models … … 11 13 } 12 14 [Required] 15 [JsonProperty("Email")] 13 16 public string Email { get; set; } 14 17 [Required] 18 [JsonProperty("Name")] 15 19 public string Name { get; set; } 16 20 [Required] 21 [JsonProperty("Passwd")] 17 22 public string Password { get; set; } 18 public List<MedicineList> MedicineLists { get; set; } 19 public List<Pharmacy> PharmaciesList { get; set; } 23 [JsonProperty("PharmacyMedicines")] 24 public List<Medicine> MedicineList { get; set; } 25 [Required] 26 [JsonProperty("Pharmacy")] 27 public ICollection<Pharmacy> PharmaciesList { get; set; } 28 //[JsonProperty("PHMedicineList")] 29 public ICollection<PharmacyHeadMedicine> PHMedicineList { get; set; } 20 30 21 31 } -
FarmatikoData/Models/RequestPharmacyHead.cs
rad60966 r1db5673 4 4 using System.ComponentModel.DataAnnotations; 5 5 using System.Text; 6 using System.Text.Json.Serialization; 6 7 7 8 namespace FarmatikoData.Models … … 13 14 } 14 15 [Required] 16 [JsonPropertyName("PharmacyHead")] 15 17 public PharmacyHead Head { get; set; } 16 18 [Required] 19 [JsonPropertyName("Pharmacy")] 17 20 public Pharmacy Pharmacy { get; set; } 18 21 -
FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs
rad60966 r1db5673 18 18 Task<bool> Remove(int id); 19 19 Task<bool> RemoveClaimingRequest(int id); 20 PharmacyHeadGetPharmacyHead(string userName);20 object GetPharmacyHead(string userName); 21 21 } 22 22 } -
FarmatikoServices/Services/PHService.cs
rad60966 r1db5673 13 13 { 14 14 private readonly IPHRepo _iPHRepo; 15 public PHService(IPHRepo iPHRepo) 15 private readonly IRepository _repository; 16 public PHService(IPHRepo iPHRepo, IRepository repository) 16 17 { 17 18 _iPHRepo = iPHRepo; 19 _repository = repository; 18 20 } 19 21 … … 55 57 56 58 59 57 60 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead) 58 61 { 59 62 if (pharmacyHead != null) 60 await _iPHRepo.UpdatePharmacyHead(pharmacyHead); 63 { 64 var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email); 65 66 if (pharmacyHead.PharmaciesList.Count() == 0) 67 pharmacyHead.PharmaciesList = null; 68 if (pharmacyHead.MedicineList.Count() == 0) 69 pharmacyHead.MedicineList = null; 70 71 phead.PHMedicineList = _repository.GetPHMedicines(phead.Email); 72 73 if (phead.MedicineList != pharmacyHead.MedicineList || phead != pharmacyHead) 74 { 75 phead.MedicineList = pharmacyHead.MedicineList; 76 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 77 78 foreach (var med in phead.MedicineList) 79 { 80 med.Id++; 81 var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 82 { 83 PheadId = x.PheadId, 84 Head = x.Head, 85 MedicineId = x.MedicineId, 86 Medicine = x.Medicine 87 }).Where(x => x.MedicineId == med.Id).Single(); 88 list.Add(PHMObj); 89 } 90 91 phead.PHMedicineList = list; 92 93 await _iPHRepo.UpdatePharmacyHead(phead); 94 } 95 else throw new Exception("Cannot update pharmacy head since there was no changes."); 96 } 61 97 else throw new Exception("PharmacyHead has a null value."); 62 98 } … … 93 129 } 94 130 95 public PharmacyHeadGetPharmacyHead(string userName)131 public object GetPharmacyHead(string userName) 96 132 { 97 133 if (userName != null) 98 134 { 99 return _iPHRepo.GetPharmacyHeadByUserName(userName); 100 } 101 return default; 135 var Phead = _iPHRepo.GetPharmacyHeadByUserName(userName); 136 List<PharmacyHeadMedicine> PHMedicines = _iPHRepo.GetPharmacyHeadMedicines(userName); 137 List<Medicine> Medicines = _repository.GetMedicines().ToList(); 138 List<Medicine> PHMedicineList = new List<Medicine>(); 139 140 141 //var meds = PHMedicines.Where(x => x.Id == Phead.Id).ToList(); 142 var pharmacies = _iPHRepo.GetPharmacies(); 143 var PheadPharms = pharmacies.Where(x => x.PheadId == Phead.Id).ToList(); 144 var user = _repository.GetRole(userName); 145 146 147 if (user.UserRole.ToString().Equals("Admin")) 148 { 149 var Admin = new 150 { 151 Id = user.Id, 152 Email = user.Email, 153 Name = user.Name, 154 Passwd = user.Password, 155 MedicineList = PHMedicines, 156 PharmaciesList = Phead.PharmaciesList 157 }; 158 159 return Admin; 160 } 161 162 if (PheadPharms.Count() > 0) 163 Phead.MedicineList = PHMedicineList; 164 else Phead.PharmaciesList = pharmacies; 165 166 if (Phead.PHMedicineList.Count() > 0) 167 { 168 foreach (var med in Medicines) 169 { 170 var PHMObj = Phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 171 { 172 PheadId = x.PheadId, 173 Head = x.Head, 174 MedicineId = x.MedicineId, 175 Medicine = x.Medicine 176 }).Where(x => x.MedicineId == med.Id).SingleOrDefault(); 177 if (PHMObj == null || PHMObj == default) 178 break; 179 if (PHMObj.MedicineId == med.Id) 180 { 181 Medicine medicine = new Medicine(med.Name, med.Strength, med.Form, med.WayOfIssuing, med.Manufacturer, med.Price, med.Packaging); 182 PHMedicineList.Add(medicine); 183 } 184 } 185 Phead.MedicineList = PHMedicineList; 186 } 187 else 188 { 189 Phead.MedicineList = Medicines; 190 } 191 192 PharmacyHead pharHead = new PharmacyHead() 193 { 194 Id = Phead.Id, 195 MedicineList = Phead.MedicineList, 196 PharmaciesList = Phead.PharmaciesList, 197 Email = Phead.Email, 198 Name = Phead.Name, 199 Password = Phead.Password 200 }; 201 return pharHead; 202 } 203 else throw new Exception("Username is null."); 102 204 } 103 205 } -
FarmatikoServices/Services/ProcessJSONService.cs
rad60966 r1db5673 58 58 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx"; 59 59 string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx"; 60 int count = 0;61 60 Uri uri1 = new Uri(url1); 62 61 Uri uri2 = new Uri(url2); -
FarmatikoServices/Services/Service.cs
rad60966 r1db5673 44 44 public async Task<IEnumerable<Medicine>> GetMedicines() 45 45 { 46 var Medicines = await _repository.GetMedicines ();46 var Medicines = await _repository.GetMedicinesAsync(); 47 47 return Medicines; 48 48 } … … 126 126 else throw new Exception("Pharmacy is null"); 127 127 } 128 128 129 // Ovaa kontrola ja ima samo admin 129 130 public async Task AddPharmacyHead(PharmacyHead pharmacyHead) … … 131 132 if (pharmacyHead != null) 132 133 { 133 var Medicines = await _repository.GetMedicines ();134 var Medicines = await _repository.GetMedicinesAsync(); 134 135 foreach (var med in Medicines) 135 136 { 136 MedicineList medicine = new MedicineList() 137 { 138 Medicine = med, 139 HasMedicine = false 140 }; 141 pharmacyHead.MedicineLists.Add(medicine); 137 pharmacyHead.MedicineList.Add(med); 142 138 } 139 143 140 await _repository.AddPharmacyHead(pharmacyHead); 144 141 } 145 throw new Exception("PharmacyHead is null");142 else throw new Exception("PharmacyHead is null"); 146 143 } 147 144 //za json(Sys updater)
Note:
See TracChangeset
for help on using the changeset viewer.