Esempio n. 1
0
        public async Task <TemplateModel> InsertTemplate(IBusinessService service, Guid id)
        {
            var templateModel = new TemplateModel
            {
                FormTemplates = new List <FormTemplateModel>
                {
                    new FormTemplateModel
                    {
                        Labels = new List <string>()
                    }
                }
            };

            return(await service.CreateTemplate(templateModel, id));
        }
        public async Task <ActionResult <TemplateModel> > CreateTemplate(TemplateModel templateModel)
        {
            Guid?userId = null;

            try
            {
                var identity = HttpContext.User.Identity as ClaimsIdentity;
                userId        = Guid.Parse(identity.Claims.Where(claim => claim.Type == "Id").First().Value);
                templateModel = await _service.CreateTemplate(templateModel, (Guid)userId);

                return(CreatedAtAction(nameof(GetTemplates), new { id = templateModel.TemplateId }, templateModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message, stack = ex.StackTrace, userId = userId.ToString() }));
            }
        }
Esempio n. 3
0
        public async Task <ActionResult <TemplateModel> > CreateTemplate(TemplateModel templateModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    templateModel = await _service.CreateTemplate(templateModel);

                    return(CreatedAtAction(nameof(GetTemplates), new { id = templateModel.TemplateId }, templateModel));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
        public async Task <ActionResult <TemplateModel> > CreateTemplate(TemplateModel templateModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var identity = HttpContext.User.Identity as ClaimsIdentity;
                    var userId   = Guid.Parse(identity.Claims.First(claim => claim.Type == "Id").Value);
                    templateModel = await _service.CreateTemplate(templateModel, userId);

                    return(CreatedAtAction(nameof(GetTemplates), new { id = templateModel.TemplateId }, templateModel));
                }
                else
                {
                    throw new InvalidOperationException("Model state invalid.");
                }
            }
            catch
            {
                return(BadRequest());
            }
        }