public ActionResult DeliveryItem(string SerialNumber, int ItemId, string DeliveryNamePerson, string Details) { Item missingItem = new Item(); if (SerialNumber != string.Empty) { missingItem = db.Item.Where(e => e.SerialNumber == SerialNumber).FirstOrDefault(); } var item = db.Item.Find(ItemId); if (item != null) { using (var context = new AmanatakContext()) { using (DbContextTransaction dbTran = context.Database.BeginTransaction()) { try { item.Deliveried = true; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); //save in ItemsHistory var ItemsHistory = new ItemsHistory(); ItemsHistory.DeliveryTime = DateTime.UtcNow.AddHours(3); ItemsHistory.Details = Details; ItemsHistory.ItemId = ItemId; if (missingItem != null) { ItemsHistory.ItemMissingId = missingItem.Id; } db.Entry(ItemsHistory).State = EntityState.Added; db.SaveChanges(); dbTran.Commit(); } catch { dbTran.Rollback(); } } } } if (item == null) { return(HttpNotFound()); } return(RedirectToAction("Index")); }
public ActionResult Edit(MissingItemViewModel Model) { if (ModelState.IsValid) { using (var context = new AmanatakContext()) { using (DbContextTransaction dbTran = context.Database.BeginTransaction()) { try { //Save edit Item Model.Item.ItemView = true; Model.Item.UserModified = "Operatort1";//For Prototype Model.Item.DateModified = DateTime.UtcNow.AddHours(3); Model.Item.ItemCategory = ItemCategory.Found; db.Entry(Model.Item).State = EntityState.Modified; db.SaveChanges(); //Save new Image for (int i = 0; i < Model.ItemImages.Count; i++) { var file = Model.ItemImages[i]; if (file != null && file.ContentLength > 0) { string FileName = Guid.NewGuid().ToString(); file.SaveAs(Server.MapPath("~/ItemsImages/" + FileName + "-" + file.FileName)); var itemImage = new ItemImages(); itemImage.ImagePath = FileName + "-" + file.FileName; itemImage.ItemId = Model.Item.Id; db.ItemImages.Add(itemImage); db.SaveChanges(); } } dbTran.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { dbTran.Rollback(); } } } } ViewBag.ItemTypeId = new SelectList(db.ItemType, "Id", "Name", Model.Item.ItemTypeId); return(View(Model)); }
public ActionResult Edit([Bind(Include = "Id,Name,TypeId,Status")] TestClass testClass) { if (ModelState.IsValid) { db.Entry(testClass).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(testClass)); }
public ActionResult Edit(IdentificationType identificationType) { if (ModelState.IsValid) { db.Entry(identificationType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(identificationType)); }
public ActionResult Edit([Bind(Include = "Id,Name,DateCreated,UserCreated,DateModified,UserModified")] Country country) { if (ModelState.IsValid) { db.Entry(country).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(country)); }
public ActionResult Edit([Bind(Include = "Id,Name,Status")] ItemType itemType) { if (ModelState.IsValid) { itemType.UserModified = "Admin1";//For Prototype itemType.DateModified = DateTime.UtcNow.AddHours(3); db.Entry(itemType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(itemType)); }