Пример #1
0
        public async Task <IActionResult> AddColumn([FromBody] CellEditModel cellEditModel)
        {
            var rubric = await _applicationDbContext.Rubrics.Include(r => r.Rows).SingleOrDefaultAsync(x => x.Id == cellEditModel.RubricId);

            var currentUser = await _userManager.GetUserAsync(User);

            var isOwner = await _applicationDbContext.Rubrics.Where(x => x.ApplicationUserId == currentUser.Id && x.Id == cellEditModel.RubricId).AnyAsync();

            if (!isOwner)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Insufficient permissions."));
            }

            var cellIds = new List <int>();

            foreach (var row in rubric.Rows)
            {
                Cell cell = new Cell {
                    RowId = row.Id, Text = ""
                };
                row.Cells.Add(cell);

                await _applicationDbContext.SaveChangesAsync();

                cellIds.Add(cell.Id);
            }

            return(Json(cellIds));
        }
Пример #2
0
        public async Task <IActionResult> EditCell([FromBody] CellEditModel cellEditModel)
        {
            var rubric = await _applicationDbContext.Rubrics.SingleOrDefaultAsync(r => r.Id == cellEditModel.RubricId);

            if (rubric == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Rubric not found."));
            }

            var cell = await _applicationDbContext.Cells.Include(r => r.Row).SingleOrDefaultAsync(c => c.Id == cellEditModel.CellId);

            if (cell == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Cell not found."));
            }

            var row = await _applicationDbContext.Rows.Include(r => r.Rubric).SingleOrDefaultAsync(r => r.Id == cell.RowId);

            if (row == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Row not found."));
            }

            var currentUser = await _userManager.GetUserAsync(User);

            var isOwner = await _applicationDbContext.Rubrics.Where(x => x.ApplicationUserId == currentUser.Id && x.Id == row.RubricId).AnyAsync();

            if (!isOwner)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Insufficient permissions."));
            }

            cell.Text = cellEditModel.Text;

            await _applicationDbContext.SaveChangesAsync();

            return(Json("Successfully edited."));
        }