Пример #1
0
        public void AddMedicineToAllFAK(int id, FirstAidKitMedicine medicine)
        {
            var user = _context.Users.Include(x => x.UserFirstAidKits).ThenInclude(y => y.FirstAidKit).ThenInclude(X => X.FirstAidKitMedicines).FirstOrDefault(x => x.UserID == id);

            foreach (var apteczka in user.UserFirstAidKits)
            {
                apteczka.FirstAidKit.FirstAidKitMedicines.Add(new FirstAidKitMedicine {
                    MedicineID = medicine.MedicineID, RemainingQuantity = medicine.RemainingQuantity, ExpirationDate = medicine.ExpirationDate
                });
            }
        }
Пример #2
0
        public async Task <IActionResult> Delete(int id)
        {
            var fakMedicineToRemove = new FirstAidKitMedicine {
                FirstAidKitMedicineID = id
            };

            _fakRepo.Delete(fakMedicineToRemove);
            if (await _fakRepo.SaveAll())
            {
                return(NoContent());
            }

            throw new System.Exception($"Deleting FakMedicine {id} failed on save");
        }
Пример #3
0
        public static void Initialize(DataContext context)
        {
            if (context.Users.Any())
            {
                return;   // DB has been seeded
            }



            var users = new User[] {
                new User {
                    Name = "Bogdan", Surname = "Bogdanowicz", Email = "*****@*****.**"
                },
                new User {
                    Name = "Jan", Surname = "Kowalski", Email = "*****@*****.**"
                },
                new User {
                    Name = "Tomasz", Surname = "Nowak", Email = "*****@*****.**"
                },
                new User {
                    Name = "Kamil", Surname = "Limak", Email = "*****@*****.**"
                },
            };

            foreach (User u in users)
            {
                byte[] passwordHash, passwordSalt;
                CreatePasswordHash("password", out passwordHash, out passwordSalt);
                u.PasswordHash = passwordHash;
                u.PasswordSalt = passwordSalt;
                u.Name         = u.Name.ToLower();
                u.Surname      = u.Surname.ToLower();
                context.Users.Add(u);
            }
            context.SaveChanges();

            var firstAidKits = new FirstAidKit[] {
                new FirstAidKit {
                },
                new FirstAidKit {
                },
                new FirstAidKit {
                },
                new FirstAidKit {
                },
            };

            foreach (FirstAidKit fak in firstAidKits)
            {
                context.FirstAidKits.Add(fak);
            }

            context.SaveChanges();

            var userFirstAidKits = new UserFirstAidKit[] {
                new UserFirstAidKit {
                    UserID = 1, FirstAidKitID = 1, Name = "apteczka dom"
                },

                new UserFirstAidKit {
                    UserID = 1, FirstAidKitID = 2, Name = "apteczka biuro"
                },

                new UserFirstAidKit {
                    UserID = 3, FirstAidKitID = 3, Name = "apteczka dom"
                },

                new UserFirstAidKit {
                    UserID = 4, FirstAidKitID = 4, Name = "apteczka dom"
                },
            };

            foreach (UserFirstAidKit ufak in userFirstAidKits)
            {
                context.UserFirstAidKits.Add(ufak);
            }
            context.SaveChanges();

            var medicines = new Medicine[] {
                new Medicine {
                    Name = "Apap", QuantityInPackage = 10
                },
                new Medicine {
                    Name = "Ketonal", QuantityInPackage = 10
                },
                new Medicine {
                    Name = "Ibuprom", QuantityInPackage = 10
                },
                new Medicine {
                    Name = "No-Spa", QuantityInPackage = 10
                },
            };

            foreach (Medicine m in medicines)
            {
                context.Medicines.Add(m);
            }

            context.SaveChanges();
            var currentDayMinus7 = DateTime.Today.AddDays(-7);


            var firstAidKitMedicines = new FirstAidKitMedicine[] {
                new FirstAidKitMedicine {
                    FirstAidKitID = 1, MedicineID = 1, ExpirationDate = currentDayMinus7, IsTaken = true
                },
                new FirstAidKitMedicine {
                    FirstAidKitID = 1, MedicineID = 2, ExpirationDate = currentDayMinus7, IsTaken = true
                },
                new FirstAidKitMedicine {
                    FirstAidKitID = 2, MedicineID = 3, ExpirationDate = currentDayMinus7, IsTaken = false
                },
                new FirstAidKitMedicine {
                    FirstAidKitID = 2, MedicineID = 4, ExpirationDate = DateTime.Today.AddDays(7), IsTaken = false
                }
            };

            foreach (FirstAidKitMedicine fakm in firstAidKitMedicines)
            {
                fakm.RemainingQuantity = context.Medicines.FirstOrDefault(x => x.MedicineID == fakm.MedicineID).QuantityInPackage;
                context.FirstAidKitMedicines.Add(fakm);
            }

            context.SaveChanges();
        }