예제 #1
0
    public IActionResult Update([FromBody] Lecture item)
    {
        var session = HttpContext.Get <LoggableEntities>(_context);

        var allowed_items = ApiTokenValid ? _context.Lecture : _context.Lecture;

        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());
    }
예제 #2
0
    public void ChangeLogo(int id, [FromBody] Container <string> Logo)
    {
        var session = HttpContext.Get <LoggableEntities>(_context);

        var allowed_items = ApiTokenValid ? _context.Course : _context.Course;

        if (!allowed_items.Any(i => i.Id == id))
        {
            return;
        }
        var item = new Course()
        {
            Id = id, Logo = Logo.Content
        };

        _context.Course.Update(item);

        _context.Entry(item).Property(x => x.Name).IsModified        = false;
        _context.Entry(item).Property(x => x.Points).IsModified      = false;
        _context.Entry(item).Property(x => x.CreatedDate).IsModified = false;
        _context.Entry(item).Property(x => x.Logo).IsModified        = true;
        _context.SaveChanges();
    }