public async Task <IActionResult> PutHaul(int id, Haul haul) { if (id != haul.HaulId) { return(BadRequest()); } _context.Entry(haul).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HaulExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <Product> EditProductAsync(Product model) { if (model.ProductId == 0) { return(null); } var product = await _db.products.FirstOrDefaultAsync(p => p.ProductId == model.ProductId); if (product == null) { return(null); } _db.products.Attach(product); product.ProductName = model.ProductName; product.Description = model.Description; product.Price = model.Price; product.url = model.url; _db.Entry(product).Property(p => p.ProductName).IsModified = true; _db.Entry(product).Property(p => p.Description).IsModified = true; _db.Entry(product).Property(p => p.Price).IsModified = true; _db.Entry(product).Property(p => p.url).IsModified = true; await _db.SaveChangesAsync(); return(product); }
public void Delete(TEntity model, bool isadded) { if (isadded) { db.Set <TEntity>().Attach(model); } db.Entry(model).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; }
public async Task <ActionResult <Employee> > Put(int id, Employee employee) { if (id != employee.id) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { bool found = await EmployeeExists(id); if (!found) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEmployee(int id, Employee employee) { if (id != employee.id) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDock(int id, Dock dock) { if (id != dock.DockId) { return(BadRequest()); } _context.Entry(dock).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DockExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWagon(int id, Wagon wagon) { if (id != wagon.WagonId) { return(BadRequest()); } _context.Entry(wagon).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WagonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Category")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(book)); }
public async Task <Customer> EditCustomerAsync(Customer model) { if (model == null || model.CustomerID < 1) { return(null); } var cust = await _db.Customer.FirstOrDefaultAsync(x => x.CustomerID == model.CustomerID); if (cust == null) { return(null); } _db.Customer.Attach(cust); cust.Name = model.Name; //_db.Entry(cust).Property(x => x.Name).IsModified = true; _db.Entry(cust).State = EntityState.Modified; await _db.SaveChangesAsync(); return(cust); }
public async Task <Category> UpdateCategoryAsync(Category model) { if (model.Id != 0) { var category = await _db.categories.FirstOrDefaultAsync(c => c.Id == model.Id); if (category != null) { _db.categories.Attach(category); category.categoryName = model.categoryName; category.Num_of_products = model.Num_of_products; _db.Entry(category).Property(c => c.categoryName).IsModified = true; _db.Entry(category).Property(c => c.Num_of_products).IsModified = true; await _db.SaveChangesAsync(); return(category); } } return(null); }
public ActionResult Edit(Student student, Guid cons) { if (ModelState.IsValid) { student.CId = cons; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public async Task <ApplicationUser> EditUserAsync(EditUserModel model) { if (model.Id == null) { return(null); } var user = await _db.Users.FirstOrDefaultAsync(x => x.Id == model.Id); if (user == null) { return(null); } if (model.Password != user.PasswordHash) { var result = await _userManager.RemovePasswordAsync(user); if (result.Succeeded) { await _userManager.AddPasswordAsync(user, model.Password); } } _db.Users.Attach(user); user.Email = model.Email; user.UserName = model.UserName; user.EmailConfirmed = model.EmailConfirmed; user.PhoneNumber = model.PhoneNumber; user.Country = model.Country; _db.Entry(user).Property(x => x.Email).IsModified = true; _db.Entry(user).Property(x => x.UserName).IsModified = true; _db.Entry(user).Property(x => x.EmailConfirmed).IsModified = true; _db.Entry(user).Property(x => x.PhoneNumber).IsModified = true; _db.Entry(user).Property(x => x.Country).IsModified = true; await _db.SaveChangesAsync(); return(user); }
/// <summary> /// 更新 /// </summary> /// <param name="entity"></param> public virtual void Update(T entity) { var ientity = entity as IDbSetBase; if (ientity != null) { ientity.UserId = _userInfo.UserId; ientity.UpdatedDate = DateTime.Now; } _dbset.Attach(ientity as T); _dataContext.Entry(entity as T).State = EntityState.Modified; }
protected override void Seed(FitnessViewer.Infrastructure.Data.ApplicationDb context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // using (ApplicationDb db = new ApplicationDb()) { // if no data in calendar then populate it. 1980->2050 should be plenty if (db.Calendar.ToList().Count == 0) { DateTime date = new DateTime(1980, 1, 1); List <Calendar> detailsToAdd = new List <Calendar>(); while (date <= new DateTime(2050, 12, 31)) { detailsToAdd.Add(new Calendar(date)); date = date.AddDays(1); } context.Calendar.AddRange(detailsToAdd); db.SaveChanges(); } List <Calendar> nullWeekLabel = db.Calendar.Where(c => c.WeekLabel == null).ToList(); if (nullWeekLabel.Count > 0) { foreach (Calendar cal in nullWeekLabel) { // populate WeekLabel property. cal.UpdateValuesForDate(); // update db.Calendar.Attach(cal); var entry = db.Entry(cal); entry.Property(c => c.WeekLabel).IsModified = true; db.SaveChanges(); } } } }
public ActionResult Edit([Bind(Include = "UserID,Name,Age,Phone,Email,ApplicationUserId")] UserAcount userAcount) { var userId = User.Identity.GetUserId(); var checkingStudentId = db.UserAcounts.Where(c => c.ApplicationUserId == userId).First().UserID; if (ModelState.IsValid) { db.Entry(userAcount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userAcount)); }
public ActionResult Edit([Bind(Include = "GaneStatID,UserID,GameName,Status,MetaScore,LastPalayed,PlayTime")] GameStats gameStats) { var userId = User.Identity.GetUserId(); var checkingId = db.UserAcounts.Where(c => c.ApplicationUserId == userId).First().UserID; gameStats.UserID = checkingId; gameStats.GameImmage = ""; if (ModelState.IsValid) { db.Entry(gameStats).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.UserAcounts, "UserID", "Name", gameStats.UserID); return(View(gameStats)); }
public void UpdateProductUnits(TransactionData data, ApplicationDb context) { foreach (ProductsViewModel product in data.Products) { //var quantity = context.Product.Where(p => p.ID == product.ID).Select(p => p.Quantity).First(); var tmpProduct = context.Product.FirstOrDefault(p => p.ID == product.ID); var quantity = tmpProduct.Quantity; int newQuaintity = data.Type == 1 ? quantity + product.Units : quantity - product.Units; tmpProduct.Quantity = newQuaintity; Product newProduct = MapViewToProduct(product); //context.Product.Attach(newProduct); context.Entry(tmpProduct).Property(u => u.Quantity).IsModified = true; //context.Entry(tmpProduct).State = EntityState.Modified; context.SaveChanges(); } }
/// <summary> /// 更新 /// </summary> /// <param name="entity"></param> public virtual void Update(T entity) { _dbset.Attach(entity); _dataContext.Entry(entity).State = EntityState.Modified; }
/// <summary> /// Update existing metric record /// </summary> /// <param name="amended">Amended Metric details</param> internal void UpdateMetric(Metric amended) { _context.Metric.Attach(amended); _context.Entry(amended).State = EntityState.Modified; }
public void Delete(Profile element) { ApplicationDb.Entry(element).State = EntityState.Deleted; Profiles.Remove(element); }
public async Task <ActionResult> Login(string username, string password, bool rem) { if (username == null || password == null) { return(View()); } if (IsLoged(username, password)) { string id = AppAuthentication.GetIdByUserName(username); if (!string.IsNullOrEmpty(id)) { var appUser = await db.AppUsers.FindAsync(id); if (appUser != null) { if (appUser.Lockout == false) { appUser.ErrorLogCount = 0; db.AppUsers.Attach(appUser); db.Entry(appUser).Property(x => x.ErrorLogCount).IsModified = true; await db.SaveChangesAsync(); AddCookies(username, AppAuthentication.GetRoleName(username), password, rem); return(RedirectToAction("Index", "Home")); } else { if (await IsLuckoutFinished(appUser.LockTime, id)) { AddCookies(username, AppAuthentication.GetRoleName(username), password, rem); return(RedirectToAction("Index", "Home")); } else { ViewBag.msg = "تم حظر هذا الحساب مؤقتا يرجي معاودة محاولة تسجيل الدخول بعد انقضاء مدة الحظر"; return(View()); } } } } } else { if (await logError(username)) { ViewBag.msg = "نظرا لمحاولات التسجيل المتكررة والخاطئة تم اغلاق حساب " + username + " لمدة 12 ساعة"; } } return(View()); }
public async Task <IActionResult> CheckOut( int billId, string firstname, string lastname, string username, string email, string address, string country, int zip, string cardtype, string cardname, long cardnumber, DateTime expire, int cvv, int cartId, string userId) { if (!UserExists(userId)) { return(RedirectToAction(nameof(Index))); } if (!CartExists(cartId)) { TempData["fail"] = "يجب ملئ جميع البيانات بمربعات النص"; return(RedirectToAction("Cart", new { id = userId })); } bool execute = false; username = User.FindFirst(ClaimTypes.Name)?.Value; if (firstname != null && lastname != null && username != null && email != null && address != null && country != null && zip > 0) { if (db.BillingAddresses.Where(x => x.UserId == userId).Count() < 1) { BillingAddress bill = new BillingAddress(); bill.Address = address; bill.Country = country; bill.Email = email; bill.firstName = firstname; bill.lastName = lastname; bill.UserName = username; bill.Zip = zip; bill.UserId = userId; db.Add(bill); await db.SaveChangesAsync(); billId = bill.id; execute = true; } else { var bill = await db.BillingAddresses.FirstOrDefaultAsync(x => x.id == billId && x.UserId == userId); if (bill != null) { billId = bill.id; if (bill.Address != address || bill.Country != country || bill.Email != email || bill.firstName != firstname || bill.lastName != lastname || bill.UserName != username || bill.Zip != zip) { bill.Address = address; bill.Country = country; bill.Email = email; bill.firstName = firstname; bill.lastName = lastname; bill.UserName = username; bill.Zip = zip; db.BillingAddresses.Attach(bill); db.Entry(bill).Property(x => x.Address).IsModified = true; db.Entry(bill).Property(x => x.Country).IsModified = true; db.Entry(bill).Property(x => x.Email).IsModified = true; db.Entry(bill).Property(x => x.firstName).IsModified = true; db.Entry(bill).Property(x => x.lastName).IsModified = true; db.Entry(bill).Property(x => x.UserName).IsModified = true; db.Entry(bill).Property(x => x.Zip).IsModified = true; db.Entry(bill).Property(x => x.UserId).IsModified = false; await db.SaveChangesAsync(); } } } } else { TempData["fail"] = "يجب ملئ جميع البيانات بمربعات النص"; return(RedirectToAction("Cart", new { id = userId })); } if (!BillExists(billId)) { TempData["fail"] = "يجب ملئ جميع البيانات بمربعات النص"; return(RedirectToAction("Cart", new { id = userId })); } if (execute || db.BillingAddresses.Where(x => x.UserId == userId).Count() > 0) { if (cardtype != null && cardname != null && cardnumber > 0 && expire != null && cvv > 0) { Payment pay = new Payment(); pay.billingId = billId; pay.cardName = cardname; pay.cardNumber = cardnumber; pay.cardType = cardtype; pay.cartId = cartId; pay.cvv = cvv; pay.expiration = expire; pay.UserId = userId; db.Add(pay); await db.SaveChangesAsync(); TempData["success"] = "تم حفظ جميع البيانات بنجاح"; } else { TempData["fail"] = "يجب ملئ جميع البيانات بمربعات النص"; return(RedirectToAction("Cart", new { id = userId })); } } return(RedirectToAction("Cart", new { id = userId })); }
public void Update(Profile element) { ApplicationDb.Entry(element).State = EntityState.Modified; }