public void GetEditDetail1(EditViewModel insert)
        {
            using (var en = new TraineeEntities())
            {
                var dtls  = en.UserDetails.Where(x => x.UserId == insert.UserId).FirstOrDefault();
                var dtls1 = en.CarDetails.Where(x => x.UserId == insert.UserId).ToList();

                //var dtls1 = en.CarDetails.Where(x => x.UserId == insert.UserId).FirstOrDefault();

                dtls.FullName      = insert.FullName;
                dtls.UserEmail     = insert.UserEmail;
                dtls.PasswordHash  = insert.PasswordHash;
                dtls.CivilIdNumber = insert.CivilIdNumber;

                // dtls1.CarLicense = insert.CarDetails.AddRange();
                en.Entry(dtls).State = EntityState.Modified;

                foreach (var car in insert.CarDetails)
                {
                    var userCar = dtls1.Where(x => x.Id == car.Id).FirstOrDefault();

                    userCar.CarLicense = car.CarLicenseValue;

                    en.Entry(userCar).State = EntityState.Modified;
                }

                en.SaveChanges();
            }
        }
예제 #2
0
        public void GetEditDetail(EditViewModel insert)
        {
            using (var us = new TraineeEntities())
            {
                var viewModel  = us.UserDetails.Where(x => x.UserId == insert.UserId).FirstOrDefault();
                var viewModel1 = us.CarDetails.Where(x => x.UserId == insert.UserId).ToList();

                viewModel.FullName      = insert.FullName;
                viewModel.UserEmail     = insert.UserEmail;
                viewModel.CivilIdNumber = insert.CivilIdNumber;

                us.Entry(viewModel).State = EntityState.Modified;

                foreach (var car in insert.CarDetails)
                {
                    var userCar = viewModel1.Where(x => x.Id == car.Id).FirstOrDefault();

                    userCar.CarLicense = car.CarNumberPlate;

                    us.Entry(userCar).State = EntityState.Modified;
                }

                us.SaveChanges();
            }
        }
 public void GetDeleteDetail(int?id)
 {
     using (var dbContext = new TraineeEntities())
     {
         var user = dbContext.UserDetails.Where(x => x.UserId == id).FirstOrDefault();
         var car  = dbContext.CarDetails.Where(x => x.UserId == id).ToList();
         user.IsActive = false;
         dbContext.Entry(user).State = EntityState.Modified;
         dbContext.UserDetails.Remove(user);
         if (car.Count() > 0)
         {
             dbContext.CarDetails.RemoveRange(car)
             ;
         }
         dbContext.SaveChanges();
     }
 }
예제 #4
0
        public void Delete(int id)
        {
            using (var us = new TraineeEntities())
            {
                var viewModel  = us.UserDetails.Where(x => x.UserId == id).FirstOrDefault();
                var viewModel1 = us.CarDetails.Where(x => x.UserId == id).ToList();
                viewModel.IsActive = false;
                //viewModel.IsActive = true;
                us.Entry(viewModel).State = EntityState.Modified;
                if (viewModel1.Count() > 0)
                {
                    us.CarDetails.RemoveRange(viewModel1);
                }

                us.SaveChanges();
            }
        }