public void Test_LockForEditing() { try { User iUser = UsersRepository.Instance.GetAllUsers().First(); Assert.IsNull(iUser.Lock_); using (DataContext testContext = new DataContext(connection)) { User testUser = testContext.Users.Find(iUser.ID); testContext.Lock<User>(testUser); testContext.Entry(testUser).Reload(); Assert.IsNotNull(testUser.Lock_); testContext.Unlock<User>(testUser); Assert.IsNull(iUser.Lock_); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Update(User user) { _context.Users.Attach(user); _context.Entry(user).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); }
public void Insert(Water entity) { _context.Entry(entity).State = EntityState.Added; _context.SaveChanges(); }
public virtual void Update(T entity) { Set <T>().Attach(entity); DataContext.Entry(entity).State = EntityState.Modified; }
/*public BaseResponse BatchUpdateKpiTargetss(BatchUpdateTargetRequest request) * { * var response = new BaseResponse(); * try * { * int i = 0; * foreach (var item in request.BatchUpdateKpiTargetItemRequest) * { * var kpiTarget = item.MapTo<KpiTarget>(); * var exist = DataContext.KpiTargets.FirstOrDefault(x => x.Kpi.Id == item.KpiId && x.PeriodeType == item.PeriodeType && x.Periode == item.Periode && x.Value == item.Value && x.Remark == item.Remark); * //skip no change value * if (exist != null) * { * continue; * } * var attachedEntity = DataContext.KpiTargets.FirstOrDefault(x => x.Kpi.Id == item.KpiId && x.PeriodeType == item.PeriodeType && x.Periode == item.Periode); * if (attachedEntity != null) * { * kpiTarget.Id = attachedEntity.Id; * } * //jika tidak ada perubahan di skip aja * //if (existing.Value.Equals(item.Value) && existing.Periode.Equals(item.Periode) && existing.Kpi.Id.Equals(item.KpiId) && existing.PeriodeType.Equals(item.PeriodeType)) { * // break; * //} * if (kpiTarget.Id != 0) * { * //var attachedEntity = DataContext.KpiAchievements.Find(item.Id); * if (attachedEntity != null && DataContext.Entry(attachedEntity).State != EntityState.Detached) * { * DataContext.Entry(attachedEntity).State = EntityState.Detached; * } * DataContext.KpiTargets.Attach(kpiTarget); * DataContext.Entry(kpiTarget).State = EntityState.Modified; * } * else * { * kpiTarget.Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == item.KpiId); * DataContext.KpiTargets.Add(kpiTarget); * } * i++; * } * DataContext.SaveChanges(); * response.IsSuccess = true; * if (i > 0) * { * response.Message = string.Format("{0} KPI Target items has been updated successfully", i.ToString()); * } * else * { * response.Message = "File Successfully Parsed, but no data changed!"; * } * * * } * catch (InvalidOperationException invalidOperationException) * { * response.Message = invalidOperationException.Message; * } * catch (ArgumentNullException argumentNullException) * { * response.Message = argumentNullException.Message; * } * return response; * }*/ public BaseResponse BatchUpdateKpiTargetss(BatchUpdateTargetRequest request) { var response = new BaseResponse(); try { int deletedCounter = 0; int updatedCounter = 0; int addedCounter = 0; int skippedCounter = 0; foreach (var item in request.BatchUpdateKpiTargetItemRequest) { if (!string.IsNullOrEmpty(item.Value)) { var existedKpiTarget = DataContext.KpiTargets.FirstOrDefault( x => x.Kpi.Id == item.KpiId && x.PeriodeType == item.PeriodeType && x.Periode == item.Periode); if (existedKpiTarget != null) { if (item.Value.Equals("-") || item.Value.ToLowerInvariant().Equals("null")) { DataContext.KpiTargets.Remove(existedKpiTarget); deletedCounter++; } else { if (existedKpiTarget.Value.Equals(item.RealValue)) { skippedCounter++; } else { existedKpiTarget.Value = item.RealValue; DataContext.Entry(existedKpiTarget).State = EntityState.Modified; updatedCounter++; } } } else { var kpiTarget = item.MapTo <KpiTarget>(); if (kpiTarget.Value.HasValue) { kpiTarget.Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == item.KpiId); DataContext.KpiTargets.Add(kpiTarget); addedCounter++; } else { skippedCounter++; } } } } DataContext.SaveChanges(); response.IsSuccess = true; response.Message = string.Format("{0} data has been added, {1} data has been updated, {2} data has been removed, {3} data didn't change", addedCounter.ToString() , updatedCounter.ToString(), deletedCounter.ToString(), skippedCounter.ToString()); } catch (InvalidOperationException invalidOperationException) { response.Message = invalidOperationException.Message; } catch (ArgumentNullException argumentNullException) { response.Message = argumentNullException.Message; } return(response); }
public virtual void Update(TEntity entity) { dbSet.Attach(entity); context.Entry(entity).State = EntityState.Modified; }
public void updateGroup(int id, string n, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.Groups.Where(orig => orig.GroupID == id).FirstOrDefault(); if (original != null) { if (!original.Name.Equals(n)) { original.Name = n; original.TimeStamp = timestamp; db.Groups.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public Task UpdateTask(TaskModel task) { Task tempTask; try { Member opMember = null; if (task.MemberId.HasValue) { opMember = DataContext.Members.SingleOrDefault(m => m.Id == task.MemberId); } var opTask = new Task() { Id = task.Id, Name = task.Name, Description = task.Description, ExpectedTaskDuration = task.ExpectedDurationTime.HasValue ? task.ExpectedDurationTime.Value : 0, Duration = task.DurationTime.HasValue ? task.DurationTime.Value : 0, Status = (Status)(task.Status.HasValue ? task.Status.Value : 0), Member = opMember }; var x = DataContext.Tasks.Attach(opTask); var entry = DataContext.Entry(opTask); if (!String.IsNullOrEmpty(task.Name)) { entry.Property(e => e.Name).IsModified = true; } if (!String.IsNullOrEmpty(task.Description)) { entry.Property(e => e.Description).IsModified = true; } if (task.ExpectedDurationTime.HasValue) { entry.Property(e => e.ExpectedTaskDuration).IsModified = true; } if (task.DurationTime.HasValue) { entry.Property(e => e.Duration).IsModified = true; } if (task.Status.HasValue) { entry.Property(e => e.Status).IsModified = true; } if (task.MemberId.HasValue) { entry.Property(e => e.MemberId).IsModified = true; } tempTask = x.Entity; base.DataContext.SaveChanges(); } catch (Exception ex) { throw ex; } return(tempTask); }
public void Update <T>(T item) { data.Entry(item).State = EntityState.Modified; }
public void updateGV(int id, string value, string date, int regId, int gradeId, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.GradeValues.Include("Registration").Include("Grade").Where(orig => orig.GradeValueID == id).FirstOrDefault(); if (original != null) { if (regId != original.Registration.RegistrationID || gradeId != original.Grade.GradeID) { if (isGrade(gradeId, regId)) { MessageBox.Show("Student already have this grade value.", "GradeValue Update Error"); return; } var reg = db.Registrations.Find(regId); original.Registration = reg; var g = db.Grades.Find(gradeId); original.Grade = g; } if (!string.IsNullOrEmpty(value)) { original.Value = value.ToUpper(); } if (!string.IsNullOrEmpty(date)) { original.Date = date; } original.TimeStamp = timestamp; db.GradeValues.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbUpdateException ex) { MessageBox.Show("GradeValue Update Error", "GradeValue Update Error"); return; } catch (DbEntityValidationException e) { throw; } }
public void updateGrade(int id, string gradeName, string maxValue, int realId, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.Grades.Include("Realisation").Where(orig => orig.GradeID == id).FirstOrDefault(); if (original != null) { if (realId != original.Realisation.RealisationID) { var real = db.Realisations.Find(realId); original.Realisation = real; } if (!string.IsNullOrEmpty(maxValue)) { string Stud = string.Empty; List<GradeValue> gv = db.GradeValues.Include("Grade").Include("Registration").Include("Registration.Student").Where(o => o.Grade.GradeID == id).ToList(); if (gv != null) { foreach(GradeValue v in gv) { if (!Validation(maxValue, v.Value)) { Stud = string.Concat(Stud, "\n", v.Registration.Student.LastName); Console.WriteLine(v.Registration.Student.LastName); } } if (!string.IsNullOrEmpty(Stud)) { MessageBox.Show("You have to change or delete these students marks:" + Stud, "Grade MaxValue Update Error"); return; } } original.MaxValue = maxValue.ToUpper(); } if (!string.IsNullOrEmpty(gradeName)) { if (db.Grades.Include("Realisation").Where(o => o.Realisation.RealisationID == realId).Where(o => o.Name == gradeName).FirstOrDefault() != null) { MessageBox.Show("Grade name must be unique in realisation.", "Grade Update Error"); return; } original.Name = gradeName; } original.TimeStamp = timestamp; db.Grades.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbUpdateException ex) { MessageBox.Show("Grade Update Error", "Grade Update Error"); return; } catch (DbEntityValidationException e) { throw; } }
public void updateRegistration(int id, int realId, int studId, byte[] timestamp) { try { using (var db = new DataContext()) { var orig = db.Registrations.Include("Realisation").Include("Student").Where(o => o.RegistrationID == id).FirstOrDefault(); if (orig != null) { if (orig.Realisation.RealisationID != realId || orig.Student.StudentID != studId) { if (db.Registrations.Where(o => o.Realisation.RealisationID == realId).Where(o => o.Student.StudentID == studId).FirstOrDefault() != null) { MessageBox.Show("Student is already registered to this realisation.", "Realisation Update Error"); return; } else { var real = db.Realisations.Find(realId); orig.Realisation = real; var stud = db.Students.Find(studId); orig.Student = stud; orig.TimeStamp = timestamp; db.Registrations.Attach(orig); db.Entry(orig).State = EntityState.Modified; db.SaveChanges(); } } } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { throw; } }
public void updateRealisation(int id, int semId, int subId, byte[] timestamp) { try { using (var db = new DataContext()) { var orig = db.Realisations.Include("Subject").Include("Semester").Where(o => o.RealisationID == id).FirstOrDefault(); if (orig != null) { if (orig.Semester.SemesterID != semId || orig.Subject.SubjectID != subId) //jeÅli coÅ siÄ zmieniÅo { if (db.Realisations.Where(o => o.Subject.SubjectID == subId).Where(o => o.Semester.SemesterID == semId).FirstOrDefault() != null) { MessageBox.Show("There is already in this semester such subject.","Realisation Update Error"); return; } else { var sem = db.Semesters.Find(semId); orig.Semester = sem; var sub = db.Subjects.Find(subId); orig.Subject = sub; orig.TimeStamp = timestamp; db.Realisations.Attach(orig); db.Entry(orig).State = EntityState.Modified; db.SaveChanges(); } } } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { throw; } }
public void updateSemester(int id, string n, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.Semesters.Where(orig => orig.SemesterID == id).FirstOrDefault(); if (original != null) { if (!original.Name.Equals(n)) { original.Name = n; original.TimeStamp = timestamp; db.Semesters.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { throw; } }
public void updateSubject(int id, string NewSubName, string NewConspect, string NewUrl, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.Subjects.Where(orig => orig.SubjectID == id).FirstOrDefault(); if (original != null) { if (!string.IsNullOrEmpty(NewSubName)) original.Name = NewSubName; if (!string.IsNullOrEmpty(NewConspect)) original.Conspect = NewConspect; if (!string.IsNullOrEmpty(NewUrl)) original.url = NewUrl; original.TimeStamp = timestamp; db.Subjects.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { throw; } }
public async Task Update(Item item) { _context.Entry(item).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public void Update(Order order) { db.Entry(order).State = EntityState.Modified; }
public void Update(Tag item) { data.Entry(item).State = EntityState.Modified; data.SaveChanges(); }
public void Update(Employee employee) { dbContext.Entry(employee).State = EntityState.Modified; }
public ActionResult CheckOuts() { try { /* * Check if the user has logged on and redirect the user to login if not so * Send the user to registration page if not registered * Proceed to checkout if all is well */ int uid = Convert.ToInt32(Session["userID"]); //Gettting the cuurrent shopping cart var currentShoppingCart = Session["Cart"]; decimal totalprice = 0; if (Session["userID"] != null) { OrderModel newOrder = new OrderModel(); newOrder.customerID = uid; newOrder.orderDate = DateTime.Now; DateTime shippingDate = AddWorkdays(DateTime.Now, 5); newOrder.shippingDate = shippingDate; //get the customer address var getAddress = (from a in db.AddressModelSet where a.customerID == uid select a).ToList(); foreach (var address in getAddress) { string addr = address.address; string city = address.city; string postCode = address.postalCode; newOrder.shippingAddress = addr + ", " + city + ", " + postCode; } //order.shippingAddress = newOrder.status = "In Process"; //get total price foreach (var item in (List <Item>)currentShoppingCart) { totalprice = totalprice + (item.Prdcts.price + item.Quantity); newOrder.totalPrice = totalprice; } db.OrderModelSet.Add(newOrder); db.SaveChanges(); //get the orderId of the current user var getOrderID = (from o in db.OrderModelSet where o.customerID == uid select o).ToList(); int orderID = 0; foreach (var o in getOrderID) { orderID = o.orderID; } // var listOrderDetails = new List<OrderDetailsModel>(); foreach (var item in (List <Item>)currentShoppingCart) { var orderDetails = new OrderDetailModel(); orderDetails.orderID = orderID; orderDetails.productID = item.Prdcts.productID; orderDetails.quantityOrdered = item.Quantity; orderDetails.priceEach = item.Prdcts.price; db.OrderDetailsModelSet.Add(orderDetails); db.SaveChanges(); var query = (from p in db.ProductModelSet where p.productID == item.Prdcts.productID join od in db.OrderDetailsModelSet on p.productID equals od.productID join o in db.OrderModelSet on od.orderID equals o.orderID where o.customerID == uid select od ).ToList(); ProductModel pm = db.ProductModelSet.Find(item.Prdcts.productID); foreach (var item2 in query) { int qInStock = pm.quantityInStock - item2.quantityOrdered; pm.quantityInStock = qInStock; } db.Entry(pm).State = EntityState.Modified; db.SaveChanges(); } } else { return(RedirectToAction("Login", "Account")); } } catch (Exception) { } //return RedirectToAction("Login", "Account" ); // Response.Redirect("app/Views/Account/Login.html"); //var getOrder = db.OrderModelSet.Select(x => x).Where(x => x.customerID == uid).ToList(); return(View("Index")); }
public void Update(TodoItem todo) { _dataContext.Entry(todo).State = EntityState.Modified; _dataContext.SaveChanges(); }
protected DbEntityEntry <T> EntityEntry(T entity) { return(DataContext.Entry <T>(entity)); }
public virtual void AddAsync(T entity) { EntityEntry dbEntityEntry = _context.Entry <T>(entity); _context.Set <T>().Add(entity); }
public void Update(Database item) { db.Databases.Attach(item); db.Entry <Database>(item).State = EntityState.Modified; db.SaveChanges(); }
public virtual void Update(Product entity) { context.Products.Attach(entity); context.Entry(entity).State == EntityState.Modified; }
public async Task <int> Update(Product t) { context.Entry(t).State = EntityState.Modified; return(await context.SaveChangesAsync()); }
public void Edit(T item) { context.Entry(item).State = EntityState.Modified; }
public async Task <IActionResult> CreateFromOrder(int?id, SaleFromOrderViewModel viewModel) { if (ModelState.IsValid) { using (var transaction = new CommittableTransaction(new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var user = await _dataContext.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefaultAsync(); try { var sale = new Sale { StartDate = viewModel.StartDate.ToUniversalTime(), EndDate = viewModel.EndDate.ToUniversalTime(), Payment = viewModel.Payment, Deposit = viewModel.Deposit, Remarks = viewModel.Remarks, Pending = viewModel.Pending, Customer = await _dataContext.Customers.FindAsync(viewModel.CustomerId), Warehouse = await _dataContext.Warehouses.FindAsync(viewModel.WarehouseId), House = await _dataContext.Houses.FindAsync(viewModel.HouseId), DayPayment = await _dataContext.DayPayments.FindAsync(viewModel.DayPaymentId), TypePayment = await _dataContext.TypePayments.FindAsync(viewModel.TypePaymentId), Seller = await _dataContext.Sellers.FindAsync(viewModel.SellerId), Collector = await _dataContext.Collectors.FindAsync(viewModel.CollectorId), Helper = await _dataContext.Helpers.FindAsync(viewModel.HelperId), State = await _dataContext.States.FindAsync(viewModel.StateId), }; _dataContext.Sales.Add(sale); await _dataContext.SaveChangesAsync(); var payment = new Payment { Sale = await _dataContext.Sales.FindAsync(sale.Id), Customer = await _dataContext.Customers.FindAsync(sale.Customer.Id), Date = sale.StartDate, Deposit = sale.Deposit, Type = "Efectivo", Collector = await _dataContext.Collectors.FindAsync(sale.Customer.Collector.Id), Concept = await _dataContext.Concepts.FindAsync(8), }; _dataContext.Payments.Add(payment); await _dataContext.SaveChangesAsync(); var order = await _dataContext.Orders.FindAsync(id); order.State = await _dataContext.States.FindAsync(viewModel.StateId); _dataContext.Entry(order).State = EntityState.Modified; var details = _dataContext.OrderDetails.Include(od => od.Product).Where(sd => sd.Order.Id == id).ToList(); foreach (var detail in details) { var saleDetail = new SaleDetail { Name = detail.Name, Price = detail.Price, Quantity = detail.Quantity, Sale = await _dataContext.Sales.FindAsync(sale.Id), Product = await _dataContext.Products.FindAsync(detail.Product.Id), }; _dataContext.SaleDetails.Add(saleDetail); var inventory = _dataContext.Inventories.Where(i => i.Product.Id == saleDetail.Product.Id).FirstOrDefault(); inventory.Stock -= (decimal)saleDetail.Quantity; _dataContext.Entry(inventory).State = EntityState.Modified; } await _dataContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } return(RedirectToAction(nameof(Index))); } viewModel.Houses = _combosHelper.GetComboHouses(); viewModel.TypePayments = _combosHelper.GetComboTypePayments(); viewModel.DayPayments = _combosHelper.GetComboDayPayments(); viewModel.Sellers = _combosHelper.GetComboSellers(); viewModel.Helpers = _combosHelper.GetComboHelpers(); viewModel.Warehouses = _combosHelper.GetComboWarehouses(); viewModel.Details2 = _dataContext.Orders.Include(o => o.Customer).Where(o => o.Id == id).ToList(); viewModel.Details = _dataContext.OrderDetails.Include(od => od.Product).Where(sd => sd.Order.Id == id).ToList(); return(View(viewModel)); }
public void Update(Size size) { db.Entry(size).State = EntityState.Modified; }
public void Edit(Answer answer) { _context.Entry(answer).State = EntityState.Modified; }
public async Task UpdateCategory(ArticleCategory categoryView) { _context.Entry(categoryView).Property(p => p.CategoryName).IsModified = true; _context.ArticleCategories.Update(categoryView); await _context.SaveChangesAsync(); }
public void Update(Employee item) { _dataBase.Entry(item).State = EntityState.Modified; }
public void Update(T entity) { table.Attach(entity); _context.Entry(entity).State = EntityState.Modified; }
public void Alterar(Providencia obj) { _context.Entry(obj).State = EntityState.Modified; }
private async void btnGuardar_Click(object sender, EventArgs e) { try { if (!Validate(txtNombre, lblNombre)) { return; } if (!Validate(txtUsuario, lblUsuario)) { return; } if (!Validate(txtPassword, lblPassword)) { return; } if (!Validate(txtPIN, lblPIN)) { return; } if (cbPerfil.Text == "Perfil") { MessageBox.Show("Seleccione el perfil del empleado", "InformaciĆ³n", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (empleadoId == 0) { if (_context.User.Where(d => d.Codigo == txtPIN.Text || d.Usuario == txtUsuario.Text).Count() > 0) { MessageBox.Show("Debe seleccionar un PIN diferente", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var empleado = new Empleado { EmpleadoId = empleadoId, Nombre = GetValue(txtNombre, lblNombre), Telefono = GetValue(txtTelefono, lblTelefono), Correo = GetValue(txtCorreo, lblCorreo), Activo = chbActivo.Checked, Usuario = GetValue(txtUsuario, lblUsuario) }; var user = new User { Activo = chbActivo.Checked, Usuario = txtUsuario.Text, Codigo = txtPIN.Text, Password = txtPassword.Text, PerfilId = GetPerfilId(cbPerfil.Text) }; _context.Empleados.Add(empleado); _context.User.Add(user); } else { var empleado = _context.Empleados.Find(empleadoId); var user = await _context.User.SingleOrDefaultAsync(u => u.Usuario == empleado.Usuario); empleado.Correo = txtCorreo.Text; empleado.Nombre = txtNombre.Text; empleado.Telefono = txtTelefono.Text; empleado.Activo = chbActivo.Checked; empleado.Usuario = txtUsuario.Text; if (user != null) { user.Activo = chbActivo.Checked; user.Usuario = txtUsuario.Text; if (user.Codigo != txtPIN.Text) { if (_context.User.Where(d => d.Codigo == txtPIN.Text || d.Usuario == txtUsuario.Text).Count() > 0) { MessageBox.Show("Debe seleccionar un PIN diferente", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPIN.Text = user.Codigo; return; } } user.Codigo = txtPIN.Text; user.Password = txtPassword.Text; user.PerfilId = GetPerfilId(cbPerfil.Text); _context.Entry(user).State = EntityState.Modified; } else { user = new User { Activo = chbActivo.Checked, Usuario = txtUsuario.Text, Codigo = txtPIN.Text, Password = txtPassword.Text, PerfilId = GetPerfilId(cbPerfil.Text) }; _context.User.Add(user); } _context.Entry(empleado).State = EntityState.Modified; } await _context.SaveChangesAsync(); await LoadData(); funciones.ResetForm(panelFormulario); empleadoId = 0; MessageBox.Show("Datos guardados correctamente", "InformaciĆ³n", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Update(Doctor doctor) { _context.Entry(doctor).State = EntityState.Modified; }
public void Update(User item) => dataContext.Entry(item).State = EntityState.Modified;
public IActionResult Edite(Serie serie) { db.Entry(serie).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Attaches the entity to the given context with the specified state. /// </summary> /// <param name="db">The db context</param> /// <param name="state">The entity state</param> public void Attach(DataContext db, EntityState state) { db.Entry(this).State = state; }
public void updateStudent(int id, string ind, string first, string last, int groupId, byte[] timestamp) { try { using (var db = new DataContext()) { var original = db.Students.Include("Group").Where(orig => orig.StudentID == id).FirstOrDefault(); if (original != null) { if (!string.IsNullOrEmpty(first)) original.FirstName = first; if (!string.IsNullOrEmpty(ind)) original.IndexNo = ind; if (!string.IsNullOrEmpty(last)) original.LastName = last; if (groupId!=original.Group.GroupID ) { var group = db.Groups.Find(groupId); original.Group = group; } original.TimeStamp = timestamp; db.Students.Attach(original); db.Entry(original).State = EntityState.Modified; db.SaveChanges(); } } } catch (DbUpdateConcurrencyException ex) { throw; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }