public IActionResult AddStructure(StructureDetails structure)
        {
            try {
                //validate StructureAttributes
                dynamic structureAttr = JsonConvert.DeserializeObject(structure?.StructureAttributes);
                structure.StructureAttributes = JsonConvert.SerializeObject(structure?.StructureAttributes);
            } catch (Exception ex) {
                Util.LogInfo($"AddStructure: Issue with Deserialize StructureAttributes: {ex.Message}");
                return(StatusCode(StatusCodes.Status400BadRequest, (new { message = "Issue with Deserialize StructureAttributes", code = 400 })));
            }

            try {
                var response = _structureService.AddStructure(structure);
                return(StatusCode(StatusCodes.Status201Created, (new { message = response.Message, code = 201 })));
            } catch (ValueNotFoundException e) {
                Util.LogError(e);
                return(StatusCode(StatusCodes.Status422UnprocessableEntity, new ErrorClass()
                {
                    code = StatusCodes.Status422UnprocessableEntity.ToString(), message = e.Message
                }));
            } catch (Exception e) {
                Util.LogError(e);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ErrorClass()
                {
                    code = StatusCodes.Status500InternalServerError.ToString(), message = "Something went wrong"
                }));
            }
        }
 public IActionResult Create([FromBody] StructureDetailsVM model)
 {
     if (ModelState.IsValid)
     {
         string user           = User.Identity.Name;
         int    newStructureId = _structureService.AddStructure(model, user);
         return(CreatedAtAction(nameof(GetDetails), new { id = newStructureId }, model));
     }
     return(BadRequest());
 }
Esempio n. 3
0
        public IActionResult EditStructure(StructureDetailsVM model)
        {
            int structureId = 0;

            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    structureId = _structureService.AddStructure(model, User.Identity.Name);
                }
                else
                {
                    structureId = _structureService.EditStructure(model, User.Identity.Name);
                }
                return(RedirectToAction("StructureDetails", new { id = structureId }));
            }
            return(View(model));
        }