Beispiel #1
0
        public async Task <ActionResult <ProForm> > PostProForm(PreFormModelView Model)
        {
            var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (await userManager.IsInRoleAsync(user, "Adman") && !user.Block)
            {
                var proForm = new ProForm()
                {
                    Name = Model.Name, AName = Model.AName, ProJectTypeId = Model.ProJectTypeId, Required = Model.Required, Type = Model.Type
                };


                _context.ProForm.Add(proForm);
                _context.SaveChanges();

                return(Ok(new
                {
                    proForm.Id,
                    proForm.Name,
                    proForm.AName,
                    proForm.ProJectTypeId,
                    proForm.Required,
                    proForm.Type
                }));
            }
            else
            {
                return(Unauthorized());
            }
        }
Beispiel #2
0
        public async Task <IActionResult> PutProForm(PreFormModelView proForm)
        {
            var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (await userManager.IsInRoleAsync(user, "Adman") && !user.Block)
            {
                var form = _context.ProForm.SingleOrDefault(i => i.Id == proForm.Id);
                if (form == null)
                {
                    return(NotFound());
                }
                else
                {
                    form.Name          = proForm.Name;
                    form.AName         = proForm.AName;
                    form.Required      = proForm.Required;
                    form.Type          = proForm.Type;
                    form.ProJectTypeId = proForm.ProJectTypeId;
                }
                _context.SaveChanges();

                return(Ok(new
                {
                    form.Id,
                    form.Name,
                    form.AName,
                    form.ProJectTypeId,
                    proForm.Required,
                    proForm.Type
                }));
            }
            else
            {
                return(Unauthorized());
            }
        }