public IActionResult Update([FromBody] Asian item) { var session = HttpContext.Get <LoggableEntities>(_context); var current_User = session == null ? null : session.User; var current_Admin = session == null ? null : session.Admin; var allowed_items = ApiTokenValid ? _context.Asian : _context.Asian; if (!allowed_items.Any(i => i.Id == item.Id)) { return(Unauthorized()); } var new_item = item; var can_edit_by_token = ApiTokenValid || true; if (item == null || !can_edit_by_token) { return(Unauthorized()); } // throw new Exception("Unauthorized edit attempt"); _context.Update(new_item); _context.Entry(new_item).Property(x => x.CreatedDate).IsModified = false; _context.SaveChanges(); return(Ok()); }
private static void Init() { if (_list == null) { lock (_lock) { var list = new List <Person>(); for (int i = 0; i < TOTAL_PEOPLE; i++) { var person = (Person)null; var type = (PersonType)_random.Next(1, 5); var age = _random.Next(1, 99); var name = "Person #" + i.ToString(); switch (type) { case PersonType.Angle: person = new Angle() { Age = age, Name = name }; break; case PersonType.Asian: person = new Asian() { Age = age, Name = name }; break; case PersonType.Jute: person = new Jute() { Age = age, Name = name }; break; case PersonType.Saxon: person = new Saxon() { Age = age, Name = name }; break; } list.Add(person); } _list = list.OrderBy(x => x.Age).ToList(); } } }
public IActionResult /*Asian*/ Create() { var session = HttpContext.Get <LoggableEntities>(_context); var current_User = session == null ? null : session.User; var current_Admin = session == null ? null : session.Admin; var can_create_by_token = ApiTokenValid || true; if (!can_create_by_token) { return(Unauthorized()); } // throw new Exception("Unauthorized create attempt"); var item = new Asian() { CreatedDate = DateTime.Now, Id = _context.Categorie.Max(i => i.Id) + 1 }; _context.Asian.Add(PortableRecipes.Models.Asian.FilterViewableAttributesLocal(current_User, current_Admin)(item)); _context.SaveChanges(); item = PortableRecipes.Models.Asian.WithoutImages(item); return(Ok(item)); }
public IActionResult /*IEnumerable<Asian>*/ CreateNewCategorie_Meal_Asian(int Meal_id) { var session = HttpContext.Get <LoggableEntities>(_context); var current_User = session == null ? null : session.User; var current_Admin = session == null ? null : session.Admin; var allowed_sources = ApiTokenValid ? _context.Meal : _context.Meal; var source = allowed_sources.FirstOrDefault(s => s.Id == Meal_id); var can_create_by_token = ApiTokenValid || true; if (source == null || !can_create_by_token) { return(Unauthorized()); } // throw new Exception("Cannot create item in relation Categorie_Meals"); var can_link_by_token = ApiTokenValid || true; if (!CanAdd_Meal_Categorie_Meals(source) || !can_link_by_token) { return(Unauthorized()); } //throw new Exception("Cannot add item to relation Categorie_Meals"); var new_target = new Asian() { CreatedDate = DateTime.Now, Id = _context.Categorie.Max(i => i.Id) + 1 }; _context.Asian.Add(new_target); _context.SaveChanges(); var link = new Categorie_Meal() { Id = _context.Categorie_Meal.Max(l => l.Id) + 1, MealId = source.Id, CategorieId = new_target.Id }; _context.Categorie_Meal.Add(link); _context.SaveChanges(); return(Ok(new Asian[] { new_target })); }