public IResult <ShoppingList> DeleteItemFromList(int listId, User user, int itemId) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { var item = list.ListItems.FirstOrDefault(item => item.Id == itemId); if (item != null) { list.ListItems.Remove(item); context.Update(list); context.SaveChanges(); return(new Result <ShoppingList>("item deleted", ResultType.Success, list)); } return(new Result <ShoppingList>("No Item with this Id on the List found", ResultType.Error)); } return(new Result <ShoppingList>("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in Deleting the Item occured: \n {ex.Message}", ResultType.Error)); } }
public IResult <ShoppingList> ChangeItemName(int listId, User user, int itemId, string itemName) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { var item = list.ListItems.FirstOrDefault(xItem => xItem.Id == itemId); if (item == null) { return(new Result <ShoppingList>("No Item with this Id was found", ResultType.Error)); } item.Itemname = itemName; context.Update(item); context.SaveChanges(); return(new Result <ShoppingList>($"itemname was changed to {itemName}", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in renaming the item occured: \n {ex.Message}", ResultType.Error)); } }
public override object VisitList(ListContext context) { var type = Any; var result = (new Result()); foreach (var i in range(0, context.expression().Length - 1, 1, true, true)) { var r = (Result)(Visit(context.expression(i))); if (i == 0) { type = (string)(r.data); result.text += r.text; } else { if (type != ((string)(r.data))) { type = Any; } result.text += "," + r.text; } } result.data = (new System.Text.StringBuilder().Append(Lst).Append("<").Append(type).Append(">")).to_str(); result.text = (new System.Text.StringBuilder().Append("(new ").Append(result.data).Append("(){ ").Append(result.text).Append(" })")).to_str(); return(result); }
public static void Initialize(ListContext context) { if (!context.Tasks.Any()) { context.Tasks.AddRange( new TaskItem { Title = "Hello0", Text = "my first task0", ReleaseDate = DateTime.Now }, new TaskItem { Title = "Hello1", Text = "my first task2", ReleaseDate = DateTime.Now }, new TaskItem { Title = "Hello2", Text = "my first task2", ReleaseDate = DateTime.Now } ); context.SaveChanges(); } }
public IResult <ShoppingList> ChangeItemIsChecked(int listId, User user, int itemId, bool isChecked) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { var item = list.ListItems.FirstOrDefault(xItem => xItem.Id == itemId); if (item == null) { return(new Result <ShoppingList>("No Item with this Id was found", ResultType.Error)); } item.IsChecked = isChecked; context.Update(item); context.SaveChanges(); return(new Result <ShoppingList>($"item checked state was set to {isChecked}", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in checking the state to {isChecked} occured: \n {ex.Message}", ResultType.Error)); } }
public override object VisitList([NotNull] ListContext context) { var type = "object"; var result = new Result(); for (int i = 0; i < context.expression().Length; i++) { var r = (Result)Visit(context.expression(i)); if (i == 0) { type = (string)r.data; result.text += r.text; } else { if (type != (string)r.data) { type = "object"; } result.text += "," + r.text; } } result.data = $"{lst}<{type}>"; result.text = $"(new {result.data}(){{ {result.text} }})"; return(result); }
Span RenderBlockContent(InlineCollection inlines, ListContext list, XElement e, int blockType) { if (inlines.LastInline != null && inlines.LastInline is LineBreak == false) { inlines.AppendLineWithMargin(); } if (blockType == BLOCK_ITEM) { PopulateListNumber(inlines, list); } else { ParagraphCount++; } var span = new Span(); if (_isCode > 0) { span.FontFamily = GetCodeFont(); } if (blockType == BLOCK_TITLE) { span.FontWeight = System.Windows.FontWeights.Bold; } inlines.Add(span); InternalRender(e, span.Inlines, list); if (blockType != BLOCK_ITEM && e.NextNode != null && IsInlineElementName((e.NextNode as XElement)?.Name.LocalName) == false) { inlines.Add(new LineBreak()); } return(span); }
private RunProcessDetails GetListRunProcessDetails(ListContext context) { return(new RunProcessDetails { Exe = "sc.exe", Args = "query state= all" }); }
private async Task SetSectionsAsync(ListContext listContext) { if (UIResolver == null) { return; } Sections = await listContext.EditContexts.ToListAsync(async editContext => (editContext, await UIResolver.GetSectionsForEditContextAsync(editContext))); }
public override int Create(InventoryItem data) { if (ListContext.Any(x => x.ItemId == data.ItemId)) { ListContext.Where(x => x.ItemId == data.ItemId).First().Amount += data.Amount; } else { ListContext.Add(data); } return(data.InventoryItemId); }
private IEnumerable <string> ProcessListOutput(ListContext context) { var lines = context.Output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) .Where(x => x.StartsWith("SERVICE_NAME: ")) .Select(x => x.Replace("SERVICE_NAME: ", "")) .Where(x => String.IsNullOrWhiteSpace(context.Args.Name) || x.ToLower().Contains(context.Args.Name.ToLower())).ToList(); var count = lines.Count; lines.Add($"{count} service{(count == 1 ? "" : "s")} found"); return(lines); }
public IResult <List <ShoppingList> > GetAllListsForUser(User user) { using var context = new ListContext(); try { var lists = context?.ShoppingList?.Where(list => list.UserId == user.Id).Include(list => list.ListItems).ToList(); return(new Result <List <ShoppingList> >("Lists found", ResultType.Success, lists)); } catch (Exception ex) { return(new Result <List <ShoppingList> >($"An Error in getting the Lists for the user occured: \n {ex.Message}", ResultType.Error)); } }
public IResult <object> AddToDb(User user) { using var context = new ListContext(); try { context.Users.Add(user); context.SaveChanges(); return(new Result($"User {user.Username} successfully added", ResultType.Success)); } catch (Exception ex) { return(new Result($"The User could not be added because of an error: \n {ex.Message}", ResultType.Error)); } }
private static FormContext NewList(params FormContext[] forms) { var list = new ListContext(null, 0); foreach (var element in forms) { list.AddChild(element); element.Parent = list; } var form = new FormContext(null, 0); form.AddChild(list); return(form); }
public int Create(object data) { var inventoryItem = InventoryItemCast(data); if (ListContext.Any(x => x.ItemId == inventoryItem.ItemId)) { ListContext.SingleOrDefault(x => x.ItemId == inventoryItem.ItemId).Amount += inventoryItem.Amount; } else { ListContext.Add(inventoryItem); } return(inventoryItem.InventoryItemId); }
private IResult <ShoppingList> AddToDb(ShoppingList list) { using var context = new ListContext(); try { var newEntry = context.ShoppingList.Add(list); context.SaveChanges(); return(new Result <ShoppingList>($"List {list.Listname} successfully added", ResultType.Success, newEntry.Entity)); } catch (Exception ex) { return(new Result <ShoppingList>($"The List could not be added because of an error: \n {ex.Message}", ResultType.Error)); } }
public HelloWorldController(ListContext context) { _context = context; if (_context.ListItems.Count() == 0) { // Create a new ListItem if collection is empty, // which means you can't delete all ListItems. _context.ListItems.Add(new ListItem { Text = "Hello World!" }); _context.SaveChanges(); } }
public static void Initialize(ListContext context) { if (!context.Lists.Any()) { context.Lists.AddRange( new List { Name = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Time_start = DateTime.Now, Time_end = DateTime.Parse("25/10/2018"), category_id = 0 }, new List { Name = "Aliquam sagittis neque ac dui mollis, nec sagittis sem varius.", Time_start = DateTime.Now, Time_end = DateTime.Parse("25/10/2018"), category_id = 0 }, new List { Name = "Maecenas finibus nisi vel mi dignissim rhoncus.", Time_start = DateTime.Now, Time_end = DateTime.Parse("25/10/2018"), category_id = 0 } ); context.SaveChanges(); } /* if (!context.Categories.Any()) * { * context.Categories.AddRange( * new Category * { * Name = "Lorem", * }, * new Category * { * Name = "Aliquam", * }, * new Category * { * Name = "Maecenas", * } * ); * context.SaveChanges(); * }*/ }
void RenderBlockContent(InlineCollection inlines, ListContext list, XElement e, int blockType) { if (inlines.FirstInline != null) { inlines.AppendLineWithMargin(); } if (blockType == BLOCK_ITEM) { PopulateListNumber(inlines, list); } InternalRender(e, inlines, list); if (inlines.FirstInline == null) { inlines.Add(new LineBreak()); } }
public override void Accept(ref EntityContainer container, IPropertyVisitor visitor) { var count = container.m_Manager.GetComponentCount(container.m_Entity); var listContext = new ListContext <IList <StructProxy> > { Property = this, Value = null, Index = -1, Count = count }; // @TODO improve, split the deps HashSet <Type> primitiveTypes = new HashSet <Type>(); // try to gather the primitive types for that visitor var entityVisitor = visitor as IPrimitivePropertyVisitor; if (entityVisitor != null) { primitiveTypes = entityVisitor.SupportedPrimitiveTypes(); } else { // @TODO remove that dependency // Fallback on the optimized visitor for now primitiveTypes = OptimizedVisitor.SupportedTypes(); } if (visitor.BeginList(ref container, listContext)) { for (var i = 0; i < count; i++) { var item = Get(ref container, i, primitiveTypes); var context = new SubtreeContext <StructProxy> { Property = this, Value = item, Index = i }; if (visitor.BeginContainer(ref container, context)) { item.PropertyBag.VisitStruct(ref item, visitor); } visitor.EndContainer(ref container, context); } } visitor.EndList(ref container, listContext); }
public IResult <User> GetUserForUsername(string username) { using var context = new ListContext(); try { var user = context.Users.FirstOrDefault(u => u.Username == username); if (user == null) { return(new Result <User>($"No User with username: {username} found", ResultType.Error)); } return(new Result <User>($"User {username} found", ResultType.Success, user)); } catch (Exception ex) { return(new Result <User>(ex.Message, ResultType.Error)); } }
public IResult <ShoppingList> GetListForId(int listId) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId); if (list != null) { return(new Result <ShoppingList>("List found", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in getting the Lists for the user occured: \n {ex.Message}", ResultType.Error)); } }
public override int Create(Models.EnemyViewModel model) { var enemy = new DAL.Enemy() { AttackMax = model.AttackMax.Value, CharacterTypeId = model.CharacterTypeId.Value, AttackMin = model.AttackMin.Value, EnemyId = model.EnemyId, CurrentLife = model.CurrentLife.Value, MaxLife = model.MaxLife.Value, SpeedRun = model.SpeedRun.Value, SpeedWalk = model.SpeedWalk.Value }; ListContext.Add(enemy); return(enemy.EnemyId); }
public IResult <object> DeleteList(int listId, User user) { using var context = new ListContext(); try { var list = context?.ShoppingList?.FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { context.ShoppingList.Remove(list); context.SaveChanges(); return(new Result("list deleted", ResultType.Success)); } return(new Result("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result($"An Error in Deleting the List occured: \n {ex.Message}", ResultType.Error)); } }
public override T VisitList([NotNull] ListContext context) { string firstEl = context .forms() ?.form(0) ?.literal() ?.symbol() ?.GetText(); int scopeCount = firstEl switch { "def" => DefDeclaration(context, SymbolTable), "fn" => FnDeclaration(context, SymbolTable), "defn" => DefnDeclaration(context, SymbolTable), "let" => LetDeclaration(context, SymbolTable), "loop" => LoopDeclaration(context, SymbolTable), _ when context.forms()?.form(0)?.vector() is { }
static void PopulateListNumber(InlineCollection text, ListContext list) { string indent = list.Indent > 0 ? new string(' ', list.Indent) : String.Empty; if (list.ListType > 0) { text.Add(new Run(indent + ((int)list.ListType++).ToString() + ". ") { Foreground = ThemeHelper.SystemGrayTextBrush, FontWeight = System.Windows.FontWeights.Bold }); } else if (list.ListType == ListType.Bullet) { text.Add(new Run(list.Indent > 0 ? indent + " \u00B7 " : " \u00B7 ") { Foreground = ThemeHelper.SystemGrayTextBrush, FontWeight = System.Windows.FontWeights.Bold }); } }
public IResult <ShoppingList> ChangeListIsFavourite(int listId, User user, bool isFavourite) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { list.IsFavourite = isFavourite; context.Update(list); context.SaveChanges(); return(new Result <ShoppingList>($"list isFavourite state was set to {isFavourite}", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in checking the state to {isFavourite} occured: \n {ex.Message}", ResultType.Error)); } }
/// <summary> /// Creates a new instance of the <see cref="List"/> object. /// </summary> /// <param name="id">The list's ID.</param> /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param> public List(string id, TrelloAuthorization auth = null) { Id = id; _context = new ListContext(id, auth); _context.Synchronized += Synchronized; _board = new Field <Board>(_context, nameof(Board)); _board.AddRule(NotNullRule <Board> .Instance); _isArchived = new Field <bool?>(_context, nameof(IsArchived)); _isArchived.AddRule(NullableHasValueRule <bool> .Instance); _isSubscribed = new Field <bool?>(_context, nameof(IsSubscribed)); _isSubscribed.AddRule(NullableHasValueRule <bool> .Instance); _name = new Field <string>(_context, nameof(Name)); _name.AddRule(NotNullOrWhiteSpaceRule.Instance); _position = new Field <Position>(_context, nameof(Position)); _position.AddRule(NotNullRule <Position> .Instance); _position.AddRule(PositionRule.Instance); TrelloConfiguration.Cache.Add(this); }
public IResult <ShoppingList> AddItemToList(int listId, ListItem item) { using var context = new ListContext(); try { var list = context?.ShoppingList?.FirstOrDefault(list => list.Id == listId); if (list != null) { context.ListItem?.Add(item); context.SaveChanges(); list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId); return(new Result <ShoppingList>("item added", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in getting the Lists for the user occured: \n {ex.Message}", ResultType.Error)); } }
public IResult <ShoppingList> RenameList(int listId, User user, string listName) { using var context = new ListContext(); try { var list = context?.ShoppingList?.Include(list => list.ListItems).FirstOrDefault(list => list.Id == listId && list.UserId == user.Id); if (list != null) { list.Listname = listName; context.Update(list); context.SaveChanges(); return(new Result <ShoppingList>($"item Renamed to {listName}", ResultType.Success, list)); } return(new Result <ShoppingList>("No List for this Id and User was found", ResultType.Error)); } catch (Exception ex) { return(new Result <ShoppingList>($"An Error in Renaming the List occured: \n {ex.Message}", ResultType.Error)); } }