// POST odata/Element
        public virtual async Task<IHttpActionResult> Post(Element element)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                await MainUnitOfWork.InsertAsync(element);
            }
            catch (DbUpdateException)
            {
                if (MainUnitOfWork.Exists(element.Id))
                {
                    return Conflict();
                }
                else
                {
                    throw;
                }
            }

            return Created(element);
        }
        // PUT odata/Element(5)
        public virtual async Task<IHttpActionResult> Put([FromODataUri] int key, Element element)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != element.Id)
            {
                return BadRequest();
            }

            try
            {
                await MainUnitOfWork.UpdateAsync(element);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MainUnitOfWork.Exists(key))
                {
                    return NotFound();
                }
                else
                {
                    return Conflict();
                }
            }

            return Ok(element);
        }
Ejemplo n.º 3
0
        public ElementField(Element element, string name, ElementFieldDataType fieldType, byte sortOrder, bool? useFixedValue = null) : this()
        {
            Validations.ArgumentNullOrDefault(element, "element");
            Validations.ArgumentNullOrDefault(name, "name");
            Validations.ArgumentNullOrDefault(sortOrder, "sortOrder");

            // fixedValue fix + validations
            if (fieldType == ElementFieldDataType.Multiplier)
                useFixedValue = false;

            if ((fieldType == ElementFieldDataType.String
                || fieldType == ElementFieldDataType.Element)
                && useFixedValue.HasValue)
                throw new ArgumentException(string.Format("fixedValue cannot have a value for {0} type", fieldType), "fixedValue");

            if ((fieldType != ElementFieldDataType.String
                && fieldType != ElementFieldDataType.Element)
                && !useFixedValue.HasValue)
                throw new ArgumentException(string.Format("fixedValue must have a value for {0} type", fieldType), "fixedValue");

            if (fieldType == ElementFieldDataType.Multiplier
                && useFixedValue.Value)
                throw new ArgumentException("fixedValue cannot be true for Multiplier type", "fixedValue");

            Element = element;
            Name = name;
            DataType = (byte)fieldType;
            UseFixedValue = useFixedValue;
            SortOrder = sortOrder;
        }
Ejemplo n.º 4
0
        public ElementItem(Element element, string name) : this()
        {
            Validations.ArgumentNullOrDefault(element, "element");
            Validations.ArgumentNullOrDefault(name, "name");

            Element = element;
            Name = name;
        }
Ejemplo n.º 5
0
 public Element AddElement(string name)
 {
     var element = new Element(this, name);
     ElementSet.Add(element);
     return element;
 }