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

            if (elementFieldId != userElementField.ElementFieldId)
            {
                return BadRequest();
            }

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

            return Ok(userElementField);
        }
Exemple #2
0
        public UserElementField AddUserRating(decimal rating)
        {
            // TODO Validation?

            var userRating = new UserElementField(this, rating);

            UserElementFieldSet.Add(userRating);
            return(userRating);
        }
        // POST odata/UserElementField
        public virtual async Task<IHttpActionResult> Post(UserElementField userElementField)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            return Created(userElementField);
        }
 public UserElementField AddUserRating(User user, decimal rating)
 {
     // TODO Validation?
     var userRating = new UserElementField(user, this, rating);
     user.UserElementFieldSet.Add(userRating);
     UserElementFieldSet.Add(userRating);
     return userRating;
 }