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)); }
// GET: /FoundItems/MissingItem/Details/5 public ActionResult Details(int?id) { var item = db.Item.Include(i => i.ItemImages).Where(m => m.Id == id).FirstOrDefault(); MissingItemViewModel model = new MissingItemViewModel(); model.Item = item; model.ItemImagesList = item.ItemImages.ToList(); if (item == null) { return(HttpNotFound()); } return(View(model)); }
// GET: /Operator/MissingItem/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var ItemOwner = db.ItemOwner.Include(i => i.Item).Where(m => m.Id == id).FirstOrDefault(); MissingItemViewModel model = new MissingItemViewModel(); model.ItemOwner = ItemOwner; model.Item = ItemOwner.Item; if (ItemOwner == null) { return(HttpNotFound()); } return(View(model)); }
// GET: /FoundItems/MissingItem/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var Item = db.Item.Include(i => i.ItemImages).Where(m => m.Id == id).FirstOrDefault(); MissingItemViewModel model = new MissingItemViewModel(); model.Item = Item; ViewBag.ItemTypeId = new SelectList(db.ItemType, "Id", "Name", Item.ItemTypeId); return(View(model)); }
public ActionResult QueryForItem(string SerialNumber) { if (SerialNumber == null) { return(View()); } var ItemOwner = db.ItemOwner.Include(i => i.Item).Where(m => m.Item.SerialNumber == SerialNumber).FirstOrDefault(); if (ItemOwner == null) { TempData["Error"] = "تأكد من رقم الطلب"; return(RedirectToAction("QueryForItem", new { SerialNumber = SerialNumber })); } MissingItemViewModel model = new MissingItemViewModel(); model.ItemOwner = ItemOwner; model.Item = ItemOwner.Item; model.ItemImagesList = ItemOwner.Item.ItemImages.ToList(); return(View(model)); }
// GET: /Operator/MissingItem/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var ItemOwner = db.ItemOwner.Include(i => i.Item).Where(m => m.Id == id).FirstOrDefault(); MissingItemViewModel model = new MissingItemViewModel(); model.ItemOwner = ItemOwner; model.Item = ItemOwner.Item; if (ItemOwner == null) { return(HttpNotFound()); } ViewBag.ItemTypeId = new SelectList(db.ItemType, "Id", "Name", ItemOwner.Item.ItemTypeId); ViewBag.IdentificationID = new SelectList(db.IdentificationType, "Id", "Name", ItemOwner.IdentificationID); ViewBag.NationalityId = new SelectList(db.Countries, "Id", "Name", ItemOwner.NationalityId); return(View(model)); }
public ActionResult CreateItemMission(MissingItemViewModel input) { if (ModelState.IsValid) { using (var context = new AmanatakContext()) { using (DbContextTransaction dbTran = context.Database.BeginTransaction()) { try { //Get Last Item Id var LastId = 0; var item = db.Item.Select(e => e).FirstOrDefault(); if (item != null) { LastId = db.Item.OrderByDescending(p => p.Id).FirstOrDefault().Id; } //Save Item input.Item.UserId = 1;//For Prototype input.Item.UserType = UserType.Guest; input.Item.ItemCategory = ItemCategory.Missing; string number = String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); input.Item.SerialNumber = LastId.ToString() + number; Session["SerialNumber"] = number; input.Item.Deliveried = false; input.Item.ItemView = false; db.Item.Add(input.Item); db.SaveChanges(); //Save Owner input.ItemOwner.ItemId = input.Item.Id; db.ItemOwner.Add(input.ItemOwner); db.SaveChanges(); //Save Image for (int i = 0; i < input.ItemImages.Count; i++) { var file = input.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 = input.Item.Id; db.ItemImages.Add(itemImage); db.SaveChanges(); } } dbTran.Commit(); ViewBag.ItemTypeId = new SelectList(db.ItemType, "Id", "Name"); ViewBag.IdentificationID = new SelectList(db.IdentificationType, "Id", "Name"); ViewBag.NationalityId = new SelectList(db.Countries, "Id", "Name"); @TempData["SerialNumber"] = " <script>alert('تم تقديم الطلب برقم " + number + " ');</script>"; return(View()); } catch (Exception ex) { dbTran.Rollback(); } } } } ViewBag.IdentificationID = new SelectList(db.IdentificationType, "Id", "Name", input.ItemOwner.IdentificationID); ViewBag.NationalityId = new SelectList(db.Countries, "Id", "Name", input.ItemOwner.Nationality); ViewBag.ItemTypeId = new SelectList(db.ItemType, "Id", "Name", input.Item.ItemTypeId); return(View(input)); }
public ActionResult QueryForItem() { MissingItemViewModel model = new MissingItemViewModel(); return(View(model)); }