예제 #1
0
        public async Task <ActionResult <SheetModel> > CreateSheet(SheetModel sheetModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    sheetModel = await _service.CreateSheet(sheetModel);

                    return(CreatedAtAction(nameof(GetSheets), new { id = sheetModel.SheetId }, sheetModel));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
예제 #2
0
        public async Task <SheetModel> InsertSheet(IBusinessService service, Guid id)
        {
            var templateModel = await InsertTemplate(service, id);

            var sheetModel = new SheetModel
            {
                FormGroups = new List <FormInputGroupModel>
                {
                    new FormInputGroupModel
                    {
                        FormTemplate = templateModel.FormTemplates.First(),
                        FormInputs   = new List <string>()
                    }
                }
            };

            return(await service.CreateSheet(sheetModel, id));
        }
        /// <summary>
        /// Create a sheet if the model state is valid.
        /// </summary>
        /// <param name="sheetModel">Sheet model containing all properties of the new sheet object.</param>
        /// <returns>New sheet model of the sheet.</returns>
        public async Task <ActionResult <SheetModel> > CreateSheet(SheetModel sheetModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var identity = HttpContext.User.Identity as ClaimsIdentity;
                    var userId   = Guid.Parse(identity.Claims.First(claim => claim.Type == "Id").Value);
                    sheetModel = await _service.CreateSheet(sheetModel, userId);

                    return(CreatedAtAction(nameof(GetSheets), new { id = sheetModel.SheetId }, sheetModel));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }