Beispiel #1
0
        public Result <Apothecary> Update(Apothecary apothecary)
        {
            var result = Try(() =>
            {
                var entity = _context.Apothecaries.Find(apothecary.Id);

                if (entity == null)
                {
                    throw new Exception("Nie znaleziono aptekarza");
                }

                if (entity.RowVersion != apothecary.RowVersion)
                {
                    throw new DBConcurrencyException("Informacje o aptekarzu zostały zmienione, przez innego użytkownika");
                }

                apothecary.RowVersion++;

                _context.Entry(entity)
                .CurrentValues.SetValues(apothecary);

                _context.SaveChanges();
                return(apothecary);
            }, typeof(ApothecaryEfRepo));

            return(result);
        }
Beispiel #2
0
        public Result Edit(Doctor doctor)
        {
            var result = Try(() =>
            {
                var entity = _context.Doctors.Find(doctor.Id);

                if (entity == null)
                {
                    throw new DoctorNotFoundException(doctor.Id);
                }

                if (entity.RowVersion != doctor.RowVersion)
                {
                    throw new DBConcurrencyException("Informacje o aptekarzu zostały zmienione, przez innego użytkownika");
                }

                doctor.RowVersion++;

                _context.Entry(entity)
                .CurrentValues.SetValues(doctor);

                _context.SaveChanges();
            }, typeof(DoctorEfRepo));

            return(result);
        }
Beispiel #3
0
        public Result Edit(Medicine medicine)
        {
            var result = Try(() =>
            {
                var entity = _context.Medicines.Find(medicine.Id);

                if (entity == null)
                {
                    throw new MedicineNotFoundException(medicine.Id);
                }

                _context.Entry(medicine)
                .CurrentValues.SetValues(medicine);

                _context.SaveChanges();
            }, typeof(MedicineEfRepo));

            return(result);
        }