Exemplo n.º 1
0
        public async Task <Patient> DeletePatient(int patientId)
        {
            var patient = await _context.Patient.FindAsync(patientId);

            if (patient == null)
            {
                return(null);
            }

            patient.Active = false;

            var local = _context.Set <Patient>()
                        .Local
                        .FirstOrDefault(p => p.PatientId == patient.PatientId);

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(patient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(patient);
        }
Exemplo n.º 2
0
        public async Task <HoursWorked> DeleteHoursWorked(int hoursWorkedId)
        {
            var hoursWorked = await _context.HoursWorked.FindAsync(hoursWorkedId);

            if (hoursWorked == null)
            {
                return(null);
            }
            hoursWorked.Active = false;

            var local = _context.Set <HoursWorked>()
                        .Local
                        .FirstOrDefault(u => u.HoursWorkedId == hoursWorked.HoursWorkedId);

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(hoursWorked).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(hoursWorked);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutBooks(int id, Books books)
        {
            if (id != books.BookId)
            {
                return(BadRequest());
            }

            _context.Entry(books).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BooksExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Deletes a therapist event from the database
        /// </summary>
        /// <param name="eventId">The event id of the therapist event to delete</param>
        /// <returns>The therapist event id that was deleted</returns>
        /// <exception cref="DbUpdateConcurrencyException">Thrown if an exception occured while trying to save changes to database</exception>
        public async Task <TherapistEvent> DeleteTherapistEvent(int eventId)
        {
            var therapistEvent = await _context.TherapistEvent.FindAsync(eventId);

            if (therapistEvent is null)
            {
                return(null);
            }

            therapistEvent.Active = false;

            var local = _context.TherapistEvent.Local.FirstOrDefault(t => t.EventId == eventId);

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(therapistEvent).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(therapistEvent);
        }
Exemplo n.º 5
0
        public async Task <Therapy> DeleteTherapy(string adl)
        {
            var therapy = await _context.Therapy.FindAsync(adl);

            if (therapy == null)
            {
                return(null);
            }

            therapy.Active = false;

            var local = _context.Therapy.Local.FirstOrDefault(t => t.Adl.Equals(adl));

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(therapy).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(therapy);
        }
Exemplo n.º 6
0
        public async Task <Appointment> DeleteAppointment(int appointmentId)
        {
            var appointment = await _context.Appointment.FindAsync(appointmentId);

            if (appointment is null)
            {
                return(null);
            }

            appointment.Active = false;

            var local = _context.Appointment.Local.FirstOrDefault(a => a.AppointmentId == appointmentId);

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(appointment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(appointment);
        }
Exemplo n.º 7
0
        public async Task <User> DeleteUser(int id)
        {
            var user = await _context.User.FindAsync(id);

            if (user == null)
            {
                return(null);
            }

            user.Active = false;

            var local = _context.Set <User>()
                        .Local
                        .FirstOrDefault(u => u.UserId == user.UserId);

            _context.Entry(local).State = EntityState.Detached;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(user);
        }
Exemplo n.º 8
0
 public virtual void Delete(TEntity entity)
 {
     if (_context.Entry(entity).State == EntityState.Detached)
     {
         _context.Attach(entity);
     }
     _context.Remove(entity);
 }
Exemplo n.º 9
0
        public static void Update_Auditable(this CoreDbContext context, IEntity entity)
        {
            if (context.Entry(entity).State == EntityState.Detached)
            {
                context.Entry(entity).State = EntityState.Unchanged;
            }

            UpdateEntityFields(entity, context.UserInfo);
            UpdateInternal(context, entity);
        }
Exemplo n.º 10
0
 public int SaveOffence(Offence entity)
 {
     if (entity.OffenceId == default)
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Added;
     }
     else
     {
         context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
     }
     context.SaveChanges();
     return(entity.OffenceId);
 }
        public async Task <IActionResult> PutServiceHistory(int id, ServiceHistory serviceHistory)
        {
            if (id != serviceHistory.VehicleId)
            {
                return(BadRequest());
            }

            _context.Entry(serviceHistory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServiceHistoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> PutRestaurante([FromRoute] int id, [FromBody] RestauranteDTO restaurante)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurante.IdRestaurante)
            {
                return(BadRequest());
            }

            _context.Entry(restaurante).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestauranteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 13
0
        public async Task <IActionResult> PutProductType(string id, ProductType productType)
        {
            if (id != productType.Id)
            {
                return(BadRequest());
            }

            _context.Entry(productType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 14
0
        public async Task <IActionResult> PutCgiShift(int id, CgiShift cgiShift)
        {
            if (id != cgiShift.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cgiShift).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CgiShiftExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutIndicatorDataCcyName(int id, IndicatorDataCcyName indicatorDataCcyName)
        {
            if (id != indicatorDataCcyName.Id)
            {
                return(BadRequest());
            }

            _context.Entry(indicatorDataCcyName).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IndicatorDataCcyNameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAnswerDetails(Guid id, AnswerDetails answerDetails)
        {
            if (id != answerDetails.AnswerId)
            {
                return(BadRequest());
            }

            _context.Entry(answerDetails).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnswerDetailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 17
0
        public async Task <IActionResult> PutAccounts(string id, Accounts accounts)
        {
            if (id != accounts.Username)
            {
                return(BadRequest());
            }

            _context.Entry(accounts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 18
0
        public async Task <IActionResult> PutGiangvien(int id, Giangvien giangvien)
        {
            if (id != giangvien.MaGv)
            {
                return(BadRequest());
            }

            _context.Entry(giangvien).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GiangvienExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 19
0
        public async Task <IActionResult> UpdateCargo(Guid id, Cargo cargo)
        {
            if (id != cargo.CargoId)
            {
                return(BadRequest());
            }

            _context.Entry(cargo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CargoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 20
0
        public async Task <IActionResult> PutBillSaleDetail(string id, BillSaleDetail billSaleDetail)
        {
            if (id != billSaleDetail.Id)
            {
                return(BadRequest());
            }

            _context.Entry(billSaleDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BillSaleDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 21
0
        public async Task <IActionResult> PutWishlist(Guid id, Wishlist wishlist)
        {
            if (id != wishlist.WishlistId)
            {
                return(BadRequest());
            }

            _context.Entry(wishlist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WishlistExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 22
0
        public async Task <IActionResult> PutClass(string id, Classes classs)
        {
            if (id != classs.ClassId)
            {
                return(BadRequest());
            }

            _context.Entry(classs).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 23
0
        public async Task <IActionResult> PutChucvu(int id, Chucvu chucvu)
        {
            if (id != chucvu.MaCv)
            {
                return(BadRequest());
            }

            _context.Entry(chucvu).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChucvuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 24
0
        public async Task <IActionResult> PutSupplier(Guid id, Supplier supplier)
        {
            if (id != supplier.SupplierId)
            {
                return(BadRequest());
            }

            _context.Entry(supplier).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 25
0
        public IHttpActionResult PutSale(int id, Sale sale)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sale.Id)
            {
                return(BadRequest());
            }

            db.Entry(sale).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SaleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutSubmmit(int id, Submmit submmit)
        {
            if (id != submmit.Form_no)
            {
                return(BadRequest());
            }

            _context.Entry(submmit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubmmitExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 27
0
        public async Task <IActionResult> PutFlightSet(int id, FlightSet flightSet)
        {
            if (id != flightSet.FlightNo)
            {
                return(BadRequest());
            }

            _context.Entry(flightSet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlightSetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 28
0
        public async Task <IActionResult> PutImportInvoice(string id, ImportInvoice importInvoice)
        {
            if (id != importInvoice.Id)
            {
                return(BadRequest());
            }

            _context.Entry(importInvoice).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ImportInvoiceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 29
0
        public async Task <IActionResult> PutDbuser(string id, Dbuser dbuser)
        {
            if (id != dbuser.Id)
            {
                return(BadRequest());
            }

            _context.Entry(dbuser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DbuserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 30
0
        public async Task <IActionResult> PutPassengerSet(int id, PassengerSet passengerSet)
        {
            if (id != passengerSet.PersonId)
            {
                return(BadRequest());
            }

            _context.Entry(passengerSet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PassengerSetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }