public ActionResult Create([Bind(Include = "AssetId,SerialNumber,ModelName,PurchaseDate,PurchasePrice,Owner,Supplier,Manufacturer,TelephoneType,Number,NumberIntern,Port,Remark")] Telephone telephone) { if (ModelState.IsValid) { db.Assets.Add(telephone); UsePeriod up = new UsePeriod(telephone, db.UsePeriodStatuses .Where(x => x.Description == "nieuw toestel").First().UsePeriodStatusId); db.UsePeriods.Add(up); db.SaveChanges(); telephone.CompoundId = "T" + telephone.AssetId; CheckNumberFormat(telephone); db.SaveChanges(); return RedirectToAction("Index"); } SetCreateAndEditViewbag(telephone); return View(telephone); }
public ActionResult Index(RepairInfo repairInfo) { int assetId = int.Parse(repairInfo.CompoundId.Substring(1)); var usePeriods = db.UsePeriods .Include(u => u.Asset) .Where(u => u.Asset.AssetId == assetId) .Where(up => up.EndDate == null || up.EndDate >= DateTime.Now) .ToList(); UsePeriod newUp; if (usePeriods.Count > 0) { newUp = usePeriods[0].Copy(); newUp.UsePeriodStatusId = 3; // statusId 3 = binnen ter herstelling foreach (UsePeriod up in usePeriods) { up.EndDate = DateTime.Now; } if (usePeriods[0].UserAccount != null) { repairInfo.UserNameFunction = usePeriods[0].UserAccount.Name; if (!string.IsNullOrWhiteSpace(usePeriods[0].Function)) { repairInfo.UserNameFunction += " - " + usePeriods[0].Function; } } else { if (!string.IsNullOrWhiteSpace(usePeriods[0].Function)) { repairInfo.UserNameFunction = usePeriods[0].Function; } } } else { newUp = new UsePeriod(db.Assets.Find(assetId), 3); // statusId 3 = binnen ter herstelling } newUp.StartDate = DateTime.Now; if (string.IsNullOrWhiteSpace(newUp.Remark)) { newUp.Remark = repairInfo.Remark; } else { newUp.Remark += Environment.NewLine + repairInfo.Remark; } db.UsePeriods.Add(newUp); db.SaveChanges(); string fileName = Server.MapPath("~/Docs/Computerfiche.docx"); MemoryStream ms = new MemoryStream(); using (DocX document = DocX.Load(fileName)) { // set spaces for strings or ReplaceText will complain if they're empty if (string.IsNullOrEmpty(repairInfo.UserNameFunction)) { repairInfo.UserNameFunction = " "; } if (string.IsNullOrEmpty(repairInfo.Remark)) { repairInfo.Remark = " "; } if (string.IsNullOrEmpty(repairInfo.Reason)) { repairInfo.Reason = " "; } // ReplaceText document.ReplaceText("%Date%", string.Format("{0:d}", repairInfo.Date)); document.ReplaceText("%UserNameFunction%", repairInfo.UserNameFunction); document.ReplaceText("%CompoundId%", repairInfo.CompoundId); document.ReplaceText("%Remark%", repairInfo.Remark); document.ReplaceText("%Reason%", repairInfo.Reason); // prepare stream document.SaveAs(ms); ms.Flush(); ms.Position = 0; // save filestream for next requests TempData["repairDoc"] = File(ms, "application/msword", repairInfo.CompoundId + ".docx"); } return RedirectToAction("Index", "UsePeriods", new { searchString = assetId.ToString(), current = false, hideUitGebruik = false, category = "Computer", repair = true }); }
public ActionResult Create([Bind(Include = "AssetId,SerialNumber,ModelName,PurchaseDate,PurchasePrice,Owner,Supplier,Manufacturer,PrinterName,TonerModel,DrumModel,IpAddress,Location,Remark")] Printer printer) { if (ModelState.IsValid) { db.Assets.Add(printer); UsePeriod up = new UsePeriod(printer, db.UsePeriodStatuses .Where(x => x.Description == "nieuw toestel").First().UsePeriodStatusId); db.UsePeriods.Add(up); db.SaveChanges(); printer.CompoundId = "P" + printer.AssetId; db.SaveChanges(); return RedirectToAction("Index"); } SetCreateAndEditViewbag(printer); return View(printer); }
public ActionResult Create([Bind(Include = "AssetId,SerialNumber,ModelName,PurchaseDate,PurchasePrice,Remark,Owner,Supplier,Manufacturer,MiscellaneousType,MiscellaneousName")] Miscellaneous miscellaneous) { if (ModelState.IsValid) { db.Assets.Add(miscellaneous); UsePeriod up = new UsePeriod(miscellaneous, db.UsePeriodStatuses .Where(x => x.Description == "nieuw toestel").First().UsePeriodStatusId); db.UsePeriods.Add(up); db.SaveChanges(); miscellaneous.CompoundId = "A" + miscellaneous.AssetId; db.SaveChanges(); return RedirectToAction("Index"); } SetCreateAndEditViewbag(miscellaneous); return View(miscellaneous); }
public ActionResult Create([Bind(Include = "AssetId,SerialNumber,ModelName,PurchaseDate,PurchasePrice,Owner,Supplier,Manufacturer,Size,MaxResolution,Remark")] Monitor monitor) { if (ModelState.IsValid) { db.Assets.Add(monitor); UsePeriod up = new UsePeriod(monitor, db.UsePeriodStatuses .Where(x => x.Description == "nieuw toestel").First().UsePeriodStatusId); db.UsePeriods.Add(up); db.SaveChanges(); monitor.CompoundId = "M" + monitor.AssetId; db.SaveChanges(); return RedirectToAction("Index"); } SetCreateAndEditViewbag(monitor); return View(monitor); }
// GET: UsePeriods/Create public ActionResult Create(string category, int? oldUsePeriodId) { UsePeriod up = new UsePeriod(); up.StartDate = DateTime.Now; if (oldUsePeriodId != null) { UsePeriod oldUsePeriod = db.UsePeriods.Find(oldUsePeriodId); oldUsePeriod.EndDate = DateTime.Today; db.SaveChanges(); SetCreateAndEditViewbag(category, oldUsePeriod.AssetId, null, oldUsePeriod.UserAccountId, oldUsePeriod.Function); } else { SetCreateAndEditViewbag(category); } ViewBag.SelectedCategory = category; return View(up); }
public ActionResult Create([Bind(Include = "AssetId,SerialNumber,ModelName,PurchaseDate,PurchasePrice,Owner,Supplier,Manufacturer,ComputerName,ComputerType,OfficeVersion,OperatingSystem,Remark,ImageVersion,QualityCheck")] Computer computer) { if (ModelState.IsValid) { db.Computers.Add(computer); UsePeriod up = new UsePeriod(computer, db.UsePeriodStatuses .Where(x => x.Description == "nieuw toestel").First().UsePeriodStatusId); db.UsePeriods.Add(up); db.SaveChanges(); computer.CompoundId = "C" + computer.AssetId; db.SaveChanges(); return RedirectToAction("Index"); } SetCreateAndEditViewbag(computer); return View(computer); }