Esempio n. 1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
 public ActionResult UpdateManufacture(int ID, string Name)
 {
     try
     {
         Manufacture m = dbContext.Manufacture.Where(x => x.ID == ID).FirstOrDefault();
         m.Name = Name;
         dbContext.Entry(m).State = System.Data.Entity.EntityState.Modified;
         dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         RedirectToAction("Index", "Home");
     }
     return(RedirectToAction("Manage", "Admin"));
 }
        public async Task <IActionResult> PutClient(int id, Client client)
        {
            if (id != client.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <IActionResult> PutGarage(int id, Garage garage)
        {
            if (id != garage.GarageId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <T> Update(T entity)
        {
            // _context.Set<T>().Attach(entity);
            _context.Entry(entity).State = EntityState.Modified;
            await Save();

            return(entity);
        }
Esempio n. 6
0
 public void Delete(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var deletedEntity = context.Entry(car);
         deletedEntity.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Esempio n. 7
0
 public void Update(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var updatedEntity = context.Entry(car);
         updatedEntity.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 8
0
 public void Add(Car car)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         var addedEntity = context.Entry(car);
         addedEntity.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Esempio n. 9
0
        public void UpdateCustomer(CustomerDetailsDto customerDetailsDto)
        {
            var customer = Mapper.Map <CustomerDetails>(customerDetailsDto);

            using (var context = new CarRentalContext())
            {
                context.Customers.Attach(customer);
                context.Entry(customer).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Esempio n. 10
0
        private async Task <ReservationDetailDTO> ReservationToDTO(Reservation reservation)
        {
            await _context.Entry(reservation).Reference(c => c.Car).LoadAsync();

            await _context.Entry(reservation).Reference(c => c.PickUpLocation).LoadAsync();

            await _context.Entry(reservation).Reference(c => c.ReturnLocation).LoadAsync();

            return(new ReservationDetailDTO
            {
                ReservationNumber = reservation.ReservationNumber,
                PickUpDate = reservation.PickUpDate,
                ReturnDate = reservation.ReturnDate,
                PickUpLocation = reservation.PickUpLocation,
                ReturnLocation = reservation.ReturnLocation,
                Car = reservation.Car,
                Surname = reservation.Surname,
                Age = reservation.Age,
                TotalPrice = CalculateTotalPrice(reservation.Age, reservation.Car.Price, (reservation.ReturnDate - reservation.PickUpDate).TotalHours)
            });
        }