//Models.Equipment equipmentModelToPassBack; // GET: AddEquipmentType public ActionResult Index() { var db = new CodeFirst.CodeFirst(); var EquipType = new Models.EquipmentType(); return(View(EquipType)); }
public ActionResult FromAddEquipmentScreen() { //equipmentModelToPassBack = equipmentModel; var db = new CodeFirst.CodeFirst(); var type = new Models.EquipmentType(); ViewBag.Referrer = "AddEquipment"; return(View("Index", type)); }
// GET: EquipmentType public ActionResult Index() { Models.EquipmentType myModel = new Models.EquipmentType(); if (TempData["model"] != null) { myModel = (Models.EquipmentType)TempData["model"]; TempData.Remove("model"); } return(View(myModel)); }
static private void CopyToInstance(PerformContext performContext, DbAppContext dbContext, HETSAPI.Import.EquipType oldObject, ref Models.EquipmentType instance, string systemId) { bool isNew = false; if (oldObject.Equip_Type_Id <= 0) { return; } //Add the user specified in oldObject.Modified_By and oldObject.Created_By if not there in the database Models.User modifiedBy = ImportUtility.AddUserFromString(dbContext, oldObject.Modified_By, systemId); Models.User createdBy = ImportUtility.AddUserFromString(dbContext, oldObject.Created_By, systemId); if (instance == null) { isNew = true; instance = new Models.EquipmentType(); instance.Id = oldObject.Equip_Type_Id; instance.IsDumpTruck = false; // Where this is coming from? !!!!!! try { instance.ExtendHours = float.Parse(oldObject.Extend_Hours.Trim()); instance.MaximumHours = float.Parse(oldObject.Max_Hours.Trim()); instance.MaxHoursSub = float.Parse(oldObject.Max_Hours_Sub.Trim()); } catch { } try { instance.Name = oldObject.Equip_Type_Cd.Trim(); } catch { } instance.CreateTimestamp = DateTime.UtcNow; instance.CreateUserid = createdBy.SmUserId; dbContext.EquipmentTypes.Add(instance); } else { instance = dbContext.EquipmentTypes .First(x => x.Id == oldObject.Equip_Type_Id); instance.LastUpdateUserid = modifiedBy.SmUserId; try { instance.LastUpdateTimestamp = DateTime.ParseExact(oldObject.Modified_Dt.Trim().Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); } catch { } dbContext.EquipmentTypes.Update(instance); } }
// GET: EquipmentTypeDetails public ActionResult Index(string typeID) { Models.EquipmentType myModel = new Models.EquipmentType(); CodeFirst.CodeFirst db = new CodeFirst.CodeFirst(); if (typeID != null) { var intTypeID = Int32.Parse(typeID); var myEquipType = db.Equipment_Type.Where(i => i.TypeID == intTypeID).FirstOrDefault(); myModel.TypeID = myEquipType.TypeID; myModel.TypeName = myEquipType.TypeName; myModel.TypeDescription = myEquipType.TypeDescription; myModel.Removable = myEquipType.Removable; } return(View(myModel)); }
public ActionResult Create([Bind(Prefix = "")] Models.EquipmentType model) { var db = new CodeFirst.CodeFirst(); if (ModelState.IsValid) { if (db.Equipment_Type.Count() > 0) { var item = db.Equipment_Type.OrderByDescending(a => a.TypeID).FirstOrDefault(); db.Equipment_Type.Add(new CodeFirst.Equipment_Type { TypeID = item.TypeID + 1, TypeName = model.TypeName, TypeDescription = model.TypeDescription, Removable = model.Removable, }); } else { db.Equipment_Type.Add(new CodeFirst.Equipment_Type { TypeID = 1, TypeName = model.TypeName, TypeDescription = model.TypeDescription, Removable = model.Removable, }); } db.SaveChanges(); if (Request.Form["Referrer"] == "AddEquipment") { //TempData["EquipmentModel"] = equipmentModelToPassBack; return(RedirectToAction("Index", "AddEquipment")); } else { model.JavaScriptToRun = "mySuccess()"; TempData["model"] = model; return(RedirectToAction("Index", "EquipmentType")); } } return(View("Index", model)); }
public ActionResult Index(Models.EquipmentType model) { CodeFirst.CodeFirst db = new CodeFirst.CodeFirst(); if (ModelState.IsValid) { Models.EquipmentType myModel = new Models.EquipmentType(); var myEquipType = db.Equipment_Type.Where(i => i.TypeID == model.TypeID).FirstOrDefault(); myModel.TypeID = myEquipType.TypeID; myModel.TypeName = myEquipType.TypeName; myModel.TypeDescription = myEquipType.TypeDescription; myModel.Removable = myEquipType.Removable; return(View(myModel)); } return(View(model)); }
public ActionResult Modify([Bind(Prefix = "")] Models.EquipmentType model) { var db = new CodeFirst.CodeFirst(); if (ModelState.IsValid) { var EquipType = db.Equipment_Type.Where(v => v.TypeID == model.TypeID).SingleOrDefault(); if (EquipType != null) { EquipType.TypeID = model.TypeID; EquipType.TypeName = model.TypeName; EquipType.TypeDescription = model.TypeDescription; EquipType.Removable = model.Removable; db.SaveChanges(); } TempData["js"] = "myUpdateSuccess()"; return(RedirectToAction("Index", "EquipmentType")); } return(View("Index", model)); }
static public void Import(PerformContext performContext, DbAppContext dbContext, string fileLocation, string systemId) { // Check the start point. If startPoint == sigId then it is already completed int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, oldTable_Progress, BCBidImport.sigId); if (startPoint == BCBidImport.sigId) // This means the import job it has done today is complete for all the records in the xml file. { performContext.WriteLine("*** Importing " + xmlFileName + " is complete from the former process ***"); return; } try { string rootAttr = "ArrayOf" + oldTable; //Create Processer progress indicator performContext.WriteLine("Processing " + oldTable); var progress = performContext.WriteProgressBar(); progress.SetValue(0); // create serializer and serialize xml file XmlSerializer ser = new XmlSerializer(typeof(EquipType[]), new XmlRootAttribute(rootAttr)); MemoryStream memoryStream = ImportUtility.memoryStreamGenerator(xmlFileName, oldTable, fileLocation, rootAttr); HETSAPI.Import.EquipType[] legacyItems = (HETSAPI.Import.EquipType[])ser.Deserialize(memoryStream); int ii = 0; foreach (var item in legacyItems.WithProgress(progress)) { // see if we have this one already. ImportMap importMap = dbContext.ImportMaps.FirstOrDefault(x => x.OldTable == oldTable && x.OldKey == item.Equip_Type_Id.ToString()); if (importMap == null) // new entry { if (item.Equip_Type_Id > 0) { Models.EquipmentType instance = null; CopyToInstance(performContext, dbContext, item, ref instance, systemId); ImportUtility.AddImportMap(dbContext, oldTable, item.Equip_Type_Id.ToString(), newTable, instance.Id); } } else // update { Models.EquipmentType instance = dbContext.EquipmentTypes.FirstOrDefault(x => x.Id == importMap.NewKey); if (instance == null) // record was deleted { CopyToInstance(performContext, dbContext, item, ref instance, systemId); // update the import map. importMap.NewKey = instance.Id; dbContext.ImportMaps.Update(importMap); } else // ordinary update. { CopyToInstance(performContext, dbContext, item, ref instance, systemId); // touch the import map. importMap.LastUpdateTimestamp = DateTime.UtcNow; dbContext.ImportMaps.Update(importMap); } } if (ii++ % 500 == 0) // Save change to database once a while to avoid frequent writing to the database. { try { ImportUtility.AddImportMap_For_Progress(dbContext, oldTable_Progress, ii.ToString(), BCBidImport.sigId); int iResult = dbContext.SaveChangesForImport(); } catch (Exception e) { string iStr = e.ToString(); } } } try { performContext.WriteLine("*** Importing " + xmlFileName + " is Done ***"); ImportUtility.AddImportMap_For_Progress(dbContext, oldTable_Progress, BCBidImport.sigId.ToString(), BCBidImport.sigId); int iResult = dbContext.SaveChangesForImport(); } catch (Exception e) { string iStr = e.ToString(); } } catch (Exception e) { performContext.WriteLine("*** ERROR ***"); performContext.WriteLine(e.ToString()); } }