public ActionResult ListItemCreate(int?id) { if (!id.HasValue) { return(HttpBadRequest("Value List id is null")); } IGstoreDb db = GStoreDb; ValueList valueList = db.ValueLists.FindById(id.Value); if (valueList == null) { return(HttpNotFound("Value List not found. Value List id: " + id)); } ValueListItem model = GStoreDb.ValueListItems.Create(); model.SetDefaultsForNew(valueList); this.BreadCrumbsFunc = htmlHelper => this.ValueListItemBreadcrumb(htmlHelper, model, false); return(View(model)); }
public ActionResult ListItemFastAdd(int valueListId, string stringValue) { if (string.IsNullOrEmpty(stringValue)) { AddUserMessage("Item not added", "You must enter text to add a value list item", UserMessageType.Danger); return(RedirectToAction("ListItemIndex", new { id = valueListId })); } ValueList valueList = GStoreDb.ValueLists.FindById(valueListId); if (valueList == null) { return(HttpBadRequest("Value List not found by id: " + valueListId)); } if (valueList.ValueListItems.Any(vl => vl.Name.ToLower() == stringValue.ToLower())) { AddUserMessage("Item not added", "Item with name '" + stringValue.ToHtml() + "' already exists in this list. Use a different item name or remove the old item first.", UserMessageType.Danger); return(RedirectToAction("ListItemIndex", new { id = valueListId })); } ValueListItem listItem = GStoreDb.ValueListItems.Create(); listItem.SetDefaultsForNew(valueList); listItem.Name = stringValue; listItem.Description = stringValue; listItem.IsPending = false; listItem.IsString = true; listItem.StringValue = stringValue; GStoreDb.ValueListItems.Add(listItem); GStoreDb.SaveChanges(); AddUserMessage("Item added to List", "Item '" + stringValue.ToHtml() + "' [" + listItem.ValueListItemId + "] was successfully added to the list", UserMessageType.Success); return(RedirectToAction("ListItemIndex", new { id = valueListId })); }