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

            if (elementCellId != userElementCell.ElementCellId)
            {
                return BadRequest();
            }

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

            return Ok(userElementCell);
        }
Exemplo n.º 2
0
        UserElementCell AddUserCell()
        {
            if (UserElementCell != null)
            {
                throw new Exception("An element cell can't have more than one user element cell for the same user.");
            }

            var userCell = new UserElementCell(this);

            if (userCell.User != null)
            {
                userCell.User.UserElementCellSet.Add(userCell);
            }
            UserElementCellSet.Add(userCell);

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

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

            return Created(userElementCell);
        }
Exemplo n.º 4
0
        UserElementCell AddUserCell()
        {
            // Validations.ArgumentNullOrDefault(user, "user");

            //if (UserElementCellSet.Any(item => item.User == user))
            if (UserElementCell != null)
                throw new Exception("An element cell can't have more than one user element cell for the same user.");

            var userCell = new UserElementCell(this);

            if (userCell.User != null)
                userCell.User.UserElementCellSet.Add(userCell);
            //user.UserElementCellSet.Add(userCell);
            UserElementCellSet.Add(userCell);
            return userCell;
        }