Exemple #1
0
        private async Task <IHttpActionResult> Save(RelationshipFieldDTO relationshipFieldDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var isNew = relationshipFieldDTO.RelationshipFieldId == Guid.Empty;

            RelationshipField relationshipField;

            if (isNew)
            {
                relationshipField = new RelationshipField();
                DbContext.Entry(relationshipField).State = EntityState.Added;
            }
            else
            {
                relationshipField = await DbContext.RelationshipFields.SingleOrDefaultAsync(o => o.RelationshipFieldId == relationshipFieldDTO.RelationshipFieldId);

                if (relationshipField == null)
                {
                    return(NotFound());
                }

                DbContext.Entry(relationshipField).State = EntityState.Modified;
            }

            ModelFactory.Hydrate(relationshipField, relationshipFieldDTO);

            await DbContext.SaveChangesAsync();

            return(await Get(relationshipField.RelationshipFieldId));
        }
Exemple #2
0
        public async Task <IHttpActionResult> Update(Guid relationshipFieldId, [FromBody] RelationshipFieldDTO relationshipFieldDTO)
        {
            if (relationshipFieldDTO.RelationshipFieldId != relationshipFieldId)
            {
                return(BadRequest("Id mismatch"));
            }

            return(await Save(relationshipFieldDTO));
        }
Exemple #3
0
        public async Task <IHttpActionResult> Insert([FromBody] RelationshipFieldDTO relationshipFieldDTO)
        {
            if (relationshipFieldDTO.RelationshipFieldId != Guid.Empty)
            {
                return(BadRequest("Invalid RelationshipFieldId"));
            }

            return(await Save(relationshipFieldDTO));
        }