internal void AssignInitialValueAsync(List <BarcodeModel> _alerts) { try { ConstantManager.VerifiedBarcodes = _alerts; LoadOwnderAsync(); LoadAssetSizeAsync(); LoadAssetTypeAsync(); var RealmDb = Realm.GetInstance(RealmDbManager.GetRealmDbConfig()); foreach (var item in _alerts) { AssetTypeModel selectedType = null; AssetSizeModel selectedSize = null; OwnerModel selectedOwner = OwnerCollection.Where(x => x.FullName == item?.Kegs?.Partners?.FirstOrDefault()?.FullName).FirstOrDefault(); if (selectedOwner != null) { RealmDb.Write(() => { selectedOwner.HasInitial = true; }); } if (item.Tags.Count > 2) { selectedType = TypeCollection.Where(x => x.AssetType == item.Tags?[2]?.Value).FirstOrDefault(); RealmDb.Write(() => { selectedType.HasInitial = true; }); } if (item.Tags.Count > 3) { selectedSize = SizeCollection.Where(x => x.AssetSize == item.Tags?[3]?.Value).FirstOrDefault(); RealmDb.Write(() => { selectedSize.HasInitial = true; }); } MaintenaceCollection.Add( new MoveMaintenanceAlertModel { UOwnerCollection = OwnerCollection.ToList(), USizeCollection = SizeCollection.ToList(), UTypeCollection = TypeCollection.ToList(), BarcodeId = item.Barcode, SelectedUOwner = selectedOwner ?? selectedOwner, SelectedUSize = selectedSize ?? selectedSize, SelectedUType = selectedType ?? selectedType }); } } catch (Exception ex) { Crashes.TrackError(ex); } }
public ActionResult Create(AssetTypeModel assetTypeModel) { try { if (ModelState.IsValid) { _assetTypeService.CreateAssetType(assetTypeModel); TempData["Message"] = "Asset type created successfully."; TempData["MessageType"] = (int)AlertMessageTypes.Success; return(RedirectToAction("List")); } else { return(View(_assetTypeService.GetAssetTypeModel(assetCategoryID: assetTypeModel.AssetCategoryID))); } } catch (Exception e) { _logger.Error(e); TempData["Message"] = "Internal server error. Asset Type not created. Please contact administrator."; TempData["MessageType"] = (int)AlertMessageTypes.Danger; return(View(_assetTypeService.GetAssetTypeModel(assetCategoryID: assetTypeModel.AssetCategoryID))); } }
// GET: AssetType/Delete/5 public ActionResult Delete(int id) { var assetType = AssetTypeManager.GetAssetTypeById(id); var assetTypeModel = new AssetTypeModel { Id = assetType.Id, Name = assetType.Name }; return(View(assetTypeModel)); }
public static AssetType ToEntity(this AssetTypeModel model) { var entity = new AssetType() { Id = model.Id, Name = model.Name, Sort = model.Sort }; return(entity); }
public IActionResult Edit(AssetTypeModel obj) { ViewData["UserNameM"] = HttpContext.Session.GetString("name") + " " + HttpContext.Session.GetString("surname"); ViewData["department"] = HttpContext.Session.GetString("department"); if (ModelState.IsValid) { AssetTypeRepository.Update(obj); return(RedirectToAction("Index")); } return(View(obj)); }
public int UpdateAssetType(AssetTypeModel assetTypeModel) { AssetTypes assetType = _assetAssetTypeRepository.GetAssetTypeByID(assetTypeModel.ID); if (assetType != null) { assetType.Description = assetTypeModel.Description; assetType.AssetCategoryID = assetTypeModel.AssetCategoryID; } _assetAssetTypeRepository.UpdateAssetType(assetType); return(assetType.ID); }
public int CreateAssetType(AssetTypeModel assetTypeModel) { AssetTypes assetType = null; assetType = this._assetAssetTypeRepository.CreateAssetType(new AssetTypes() { Description = assetTypeModel.Description, AssetCategoryID = assetTypeModel.AssetCategoryID }); return(assetType.ID); }
/// <summary> /// 编辑 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Edit(int?id) { if (id.HasValue && id.Value > 0) { var model = this.AssetTypeService.GetTypeById(id.Value); return(View(model)); } else { AssetTypeModel model = new AssetTypeModel(); return(View(model)); } }
public AssetTypeModel Add(AssetTypeModel model) { using (var dbContext = new MissionskyOAEntities()) { var existItem = dbContext.AssetTypes.Where(it => it.Name == model.Name).FirstOrDefault(); if (existItem != null) { throw new Exception("此类别已存在."); } var entity = model.ToEntity(); dbContext.AssetTypes.Add(entity); dbContext.SaveChanges(); return(entity.ToModel()); } }
// GET: /AssetType/Edit/1 public IActionResult Edit(int?id) { ViewData["UserNameM"] = HttpContext.Session.GetString("name") + " " + HttpContext.Session.GetString("surname"); ViewData["department"] = HttpContext.Session.GetString("department"); if (id == null) { return(NotFound()); } AssetTypeModel obj = AssetTypeRepository.FindByID(id.Value); if (obj == null) { return(NotFound()); } return(View(obj)); }
/// <summary> /// 设置资产类别的属性 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool SetAttributes(AssetTypeModel model) { using (var dbContext = new MissionskyOAEntities()) { var entity = dbContext.AssetTypes.Where(it => it.Id == model.Id).FirstOrDefault(); if (entity != null) { //处理区域 var sourceTypeAttributes = dbContext.AssetTypeAttributes.Where(it => it.TypeId == model.Id).ToList(); if (model.Attributes != null && model.Attributes.Count > 0) { List <int> sourceAttributeIds = sourceTypeAttributes.Select(it => it.AttributeId).ToList(); var modelAttributeIds = model.Attributes.Select(it => it.Id).ToList().Distinct(); foreach (var id in modelAttributeIds) { //添加新的 if (!sourceAttributeIds.Contains(id)) { AssetTypeAttribute typeAttr = new AssetTypeAttribute(); typeAttr.TypeId = model.Id; typeAttr.AttributeId = id; dbContext.AssetTypeAttributes.Add(typeAttr); } sourceAttributeIds.Remove(id); } //删除 var needDeleteTypeAttributes = dbContext.AssetTypeAttributes.Where(it => sourceAttributeIds.Contains(it.AttributeId) && it.TypeId == model.Id); foreach (var item in needDeleteTypeAttributes) { dbContext.AssetTypeAttributes.Remove(item); } } else { //删除所有 foreach (var item in sourceTypeAttributes) { dbContext.AssetTypeAttributes.Remove(item); } } dbContext.SaveChanges(); } return(true); } }
public ActionResult Delete(int id, AssetTypeModel assetTypeModel) { ViewBag.ErrorMessage = ""; var assetType = AssetTypeManager.GetAssetTypeById(id); if (AssetManager.GetAllByAssetType(id).Count != 0) { // cannot delete AssetType if this type has assets in database ViewBag.ErrorMessage = "Cannot Delete Type if it has assets being tracked"; return(View(assetTypeModel)); } else { // no assets of AssetType in database so it is safe to delete AssetTypeManager.Delete(id); return(RedirectToAction("Index", "AssetType")); } }
public ActionResult Create(AssetTypeModel assetTypeModel) { try { // Create new AssetType object from model to pass into database var assetType = new AssetType { Id = assetTypeModel.Id, Name = assetTypeModel.Name }; AssetTypeManager.Add(assetType); return(RedirectToAction("Index", "Asset")); } catch { return(View()); } }
public static AssetTypeModel ToModel(this AssetType entity) { var model = new AssetTypeModel() { Id = entity.Id, Name = entity.Name, Sort = entity.Sort }; if (entity.AssetTypeAttributes != null && entity.AssetTypeAttributes.Count > 0) { model.Attributes = new List <AssetAttributeModel>(); entity.AssetTypeAttributes.OrderBy(it => it.AssetAttribute.Sort).ToList().ForEach(it => { model.Attributes.Add(it.AssetAttribute.ToModel()); }); } return(model); }
public bool Update(AssetTypeModel model) { using (var dbContext = new MissionskyOAEntities()) { var existItem = dbContext.AssetTypes.Where(it => it.Name == model.Name && it.Id != model.Id).FirstOrDefault(); if (existItem != null) { throw new Exception("此类别已存在."); } var entity = dbContext.AssetTypes.Where(it => it.Id == model.Id).FirstOrDefault(); if (entity != null) { entity.Name = model.Name; entity.Sort = model.Sort; } dbContext.SaveChanges(); return(true); } }
public ActionResult SetAttributes(AssetTypeModel model) { string action = Request["Submit"]; if (action == "cancel") { return(RedirectToAction("Index")); } try { this.AssetTypeService.SetAttributes(model); return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = ex.Message; } return(View(model)); }
public ActionResult Edit(AssetTypeModel model) { string action = Request["Submit"]; if (action == "cancel") { return(RedirectToAction("Index")); } if (string.IsNullOrEmpty(model.Name)) { ModelState.AddModelError("Name", "请输入名称."); } if (ModelState.IsValid) { try { if (model.Id > 0) { this.AssetTypeService.Update(model); } else { this.AssetTypeService.Add(model); } return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Message = ex.Message; } } return(View(model)); }
public string DeleteAssetTypeRecords(AssetTypeModel ATM) { int index = Convert.ToInt32(Request["send"]); con.Open(); SqlCommand cmd = new SqlCommand("SP_AssetsTypeCRUD", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@condition", "delete"); cmd.Parameters.AddWithValue("@atid", index); cmd.Parameters.AddWithValue("@assettype", ""); cmd.ExecuteNonQuery(); con.Close(); // check roles List <LoginModel> Lmlist = new List <LoginModel>(); con.Open(); string q = "select * from Assignment_Roles where RoleId = " + Convert.ToInt32(Session["rId"]) + ""; SqlDataAdapter da3 = new SqlDataAdapter(q, con); DataTable dt3 = new DataTable(); da3.Fill(dt3); if (dt3.Rows.Count > 0) { for (int i = 0; i < dt3.Rows.Count; i++) { LoginModel lm = new LoginModel(); lm.PageName = dt3.Rows[i]["PageName"].ToString(); lm.PageStatus = dt3.Rows[i]["PageStatus"].ToString(); lm.Action = dt3.Rows[i]["Action"].ToString(); lm.Nav1 = dt3.Rows[i]["Nav1"].ToString(); lm.Nav2 = dt3.Rows[i]["Nav2"].ToString(); Lmlist.Add(lm); } } con.Close(); //end string testString = ""; for (int i = 0; i < Lmlist.Count(); i++) { testString = Lmlist[7].Action; } con.Open(); string query = "select * from AssetsType"; SqlDataAdapter da = new SqlDataAdapter(query, con); DataTable dt = new DataTable(); da.Fill(dt); con.Close(); string data = ""; if (dt.Rows.Count > 0) { if (testString == "1,2,0" || testString == "0,2,0" || testString == "0,2,3" || testString == "0,2,3" || testString == "0,2,0") { for (int i = 0; i < dt.Rows.Count; i++) { data = data + "<tr class='nr'><td>" + dt.Rows[i]["atid"].ToString() + "</td>" + "<td>" + dt.Rows[i]["AssetsType"].ToString() + "</td>" + "<td><button type='button' id='" + dt.Rows[i]["atid"].ToString() + "' onClick='Edit(this.id)' class='btn btn-primary'>Edit</button></td></tr>"; } } if (testString == "1,0,3" || testString == "0,0,3" || testString == "0,2,3" || testString == "1,0,3" || testString == "0,0,3") { for (int i = 0; i < dt.Rows.Count; i++) { data = data + "<tr class='nr'><td>" + dt.Rows[i]["atid"].ToString() + "</td>" + "<td>" + dt.Rows[i]["AssetsType"].ToString() + "</td>" + "<td><button type='button' id='" + dt.Rows[i]["atid"].ToString() + "' class='btn btn-danger deletenotification'>Delete</button></td></tr>"; } } if (testString == "1,2,3" || testString == "0,2,3") { for (int i = 0; i < dt.Rows.Count; i++) { data = data + "<tr class='nr'><td>" + dt.Rows[i]["atid"].ToString() + "</td>" + "<td>" + dt.Rows[i]["AssetsType"].ToString() + "</td>" + "<td><button type='button' id='" + dt.Rows[i]["atid"].ToString() + "' onClick='Edit(this.id)' class='btn btn-primary'>Edit</button><button type='button' id='" + dt.Rows[i]["atid"].ToString() + "' class='btn btn-danger deletenotification'>Delete</button></td></tr>"; } } if (testString == "0,0,0") { for (int i = 0; i < dt.Rows.Count; i++) { data = data + "<tr class='nr'><td>" + dt.Rows[i]["atid"].ToString() + "</td>" + "<td>" + dt.Rows[i]["AssetsType"].ToString() + "</td>"; } } } return(data); }
public ActionResult InsertAssetFormData(AssetTypeModel ATM) { // check type string typ = ""; con.Open(); string qq1 = "select Type from users where uId = " + Convert.ToInt32(Session["uuid"]) + " "; SqlDataAdapter daa = new SqlDataAdapter(qq1, con); DataTable dtt = new DataTable(); daa.Fill(dtt); con.Close(); if (dtt.Rows.Count > 0) { typ = dtt.Rows[0]["Type"].ToString(); } //end if (typ == "Testator") { // check will status con.Open(); string qry1 = "select Will from users where Will = 1 "; SqlDataAdapter daa1 = new SqlDataAdapter(qry1, con); DataTable dtt1 = new DataTable(); daa1.Fill(dtt1); if (dtt1.Rows.Count > 0) { ViewBag.documentbtn1 = "true"; } con.Close(); //end // check codocil status con.Open(); string qry2 = "select Codocil from users where Codocil = 1 "; SqlDataAdapter daa2 = new SqlDataAdapter(qry2, con); DataTable dtt2 = new DataTable(); daa2.Fill(dtt2); if (dtt2.Rows.Count > 0) { ViewBag.documentbtn2 = "true"; } con.Close(); //end // check Poa status con.Open(); string qry4 = "select POA from users where POA = 1 "; SqlDataAdapter daa4 = new SqlDataAdapter(qry4, con); DataTable dtt4 = new DataTable(); daa4.Fill(dtt4); if (dtt4.Rows.Count > 0) { ViewBag.documentbtn3 = "true"; } con.Close(); //end // check gift deeds status con.Open(); string qry3 = "select Giftdeeds from users where Giftdeeds = 1 "; SqlDataAdapter daa3 = new SqlDataAdapter(qry3, con); DataTable dtt3 = new DataTable(); daa3.Fill(dtt3); if (dtt3.Rows.Count > 0) { ViewBag.documentbtn4 = "true"; } con.Close(); //end } else { ViewBag.showtitle = "true"; ViewBag.documentlink = "true"; } // roleassignment List <LoginModel> Lmlist = new List <LoginModel>(); con.Open(); string q = "select * from Assignment_Roles where RoleId = " + Convert.ToInt32(Session["rId"]) + ""; SqlDataAdapter da3 = new SqlDataAdapter(q, con); DataTable dt3 = new DataTable(); da3.Fill(dt3); if (dt3.Rows.Count > 0) { for (int i = 0; i < dt3.Rows.Count; i++) { LoginModel lm = new LoginModel(); lm.PageName = dt3.Rows[i]["PageName"].ToString(); lm.PageStatus = dt3.Rows[i]["PageStatus"].ToString(); lm.Action = dt3.Rows[i]["Action"].ToString(); lm.Nav1 = dt3.Rows[i]["Nav1"].ToString(); lm.Nav2 = dt3.Rows[i]["Nav2"].ToString(); Lmlist.Add(lm); } ViewBag.PageName = Lmlist; } con.Close(); //end //main Roles con.Open(); string query1 = "select count(*) from assetstype where AssetsType = '" + ATM.AssetsType + "'"; SqlCommand cmd2 = new SqlCommand(query1, con); int count = (int)cmd2.ExecuteScalar(); con.Close(); if (count > 0) { ViewBag.Message = "Duplicate"; } else { con.Open(); SqlCommand cmd = new SqlCommand("SP_AssetsTypeCRUD", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@condition", "insert"); cmd.Parameters.AddWithValue("@assettype", ATM.AssetsType); cmd.ExecuteNonQuery(); con.Close(); con.Open(); string query = "select top 1 * from AssetsType order by atId desc"; SqlDataAdapter da = new SqlDataAdapter(query, con); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { string i = dt.Rows[0]["atId"].ToString(); Session["atId"] = i; } con.Close(); ViewBag.Message = "Verified"; } ModelState.Clear(); return(View("~/Views/AssetType/AddAssetTypePageContent.cshtml")); }