Exemple #1
0
        public SingleObjectModel AddStepRequirement([FromUri] string stepUID, [FromBody] object body)
        {
            try {
                var step = ProjectItem.Parse(stepUID);

                var requirement = base.GetJsonFromBody(body);

                StepDataObject dataObject;

                if (!requirement.HasValue("uid"))
                {
                    dataObject = new StepDataObject(step, requirement);
                }
                else
                {
                    dataObject = StepDataObject.Parse(requirement.Get <string>("uid"));
                    dataObject.Update(requirement);
                }

                dataObject.Save();

                return(new SingleObjectModel(this.Request, dataObject.ToResponse(),
                                             typeof(StepDataObject).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
Exemple #2
0
        public CollectionModel GetGridFormDataSource([FromUri] string dataObjectUID,
                                                     [FromUri] string activityUID)
        {
            try {
                var dataObject = StepDataObject.Parse(dataObjectUID);

                var activity = ProjectItem.Parse(activityUID);

                FixedList <Posting> list = PostingList.GetPostings(dataObject.DataItem,
                                                                   activity,
                                                                   dataObject.DataItem.DataType);

                var data = list.Select(x => {
                    var json = x.ExtensionData.ToDictionary();

                    json.Add("uid", x.UID);

                    if (dataObject.DataItem.Terms == "Actividades.CNH.CustomGrid")
                    {
                        json = Reporting.SubtaskCNH.LoadFields(dataObject, json, activity);
                    }

                    return(json);
                });

                return(new CollectionModel(this.Request, data.ToArray()));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
Exemple #3
0
        public NoDataModel RemoveStepRequirement([FromUri] string requirementUID)
        {
            try {
                var dataObject = StepDataObject.Parse(requirementUID);

                dataObject.Delete();

                return(new NoDataModel(this.Request));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
        public SingleObjectModel RemoveUploadedFile([FromUri] string dataObjectUID,
                                                    [FromUri] string activityUID)
        {
            try {
                var dataObject = StepDataObject.Parse(dataObjectUID);
                var activity   = ProjectItem.Parse(activityUID);

                var autofill = new Autofill(dataObject, activity);

                autofill.RemoveFile();

                return(new SingleObjectModel(this.Request, autofill.ToResponse(),
                                             typeof(StepDataObject).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
Exemple #5
0
        public SingleObjectModel SetDataFormFields([FromUri] string dataObjectUID,
                                                   [FromUri] string activityUID,
                                                   [FromBody] object body)
        {
            try {
                var dataObject = StepDataObject.Parse(dataObjectUID);

                var json = JsonObject.Parse(body);

                var eventType = json.Get <string>("type");
                var formData  = JsonObject.Parse(json.Get <string>("payload/formData"));

                var activity = ProjectItem.Parse(activityUID);

                Posting posting;

                if (eventType == "created")
                {
                    posting = new Posting(dataObject.DataItem.DataType,
                                          dataObject.DataItem, activity);
                    posting.ExtensionData = formData;
                    posting.Save();
                }
                else if (eventType == "updated")
                {
                    posting = Posting.Parse(json.Get <string>("payload/uid"));
                    posting.ExtensionData = formData;
                    posting.Save();
                }
                else if (eventType == "deleted")
                {
                    posting = Posting.Parse(json.Get <string>("payload/uid"));
                    posting.Delete();
                }
                else
                {
                    throw Assertion.EnsureNoReachThisCode($"Unrecognized event {eventType}.");
                }

                return(new SingleObjectModel(this.Request, dataObject.ToResponse(activity),
                                             typeof(StepDataObject).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
Exemple #6
0
        public CollectionModel ToggleActivityDataObjectStatus([FromUri] string activityUID,
                                                              [FromUri] string dataObjectUID)
        {
            try {
                StepDataObject dataObject = StepDataObject.Parse(dataObjectUID);

                dataObject.ToggleStatus();

                var activity = ProjectItem.Parse(activityUID);

                FixedList <StepDataObject> dataObjects = StepDataObject.GetListForAction(activity);

                return(new CollectionModel(this.Request, dataObjects.ToResponse(activity),
                                           typeof(StepDataObject).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
Exemple #7
0
        public SingleObjectModel GetDataFormFields([FromUri] string dataObjectUID)
        {
            try {
                var dataObject = StepDataObject.Parse(dataObjectUID);

                var fields = dataObject.DataItem.GetFormFields();

                var values = dataObject.GetFormFields();

                foreach (DataFormField field in fields)
                {
                    if (values.ContainsKey(field.Key))
                    {
                        field.Value = Convert.ToString(values[field.Key]);
                    }
                }

                return(new SingleObjectModel(this.Request, fields,
                                             typeof(DataFormField).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }