public async Task <IHttpActionResult> EditUserDescription([FromUri] int id,
                                                                  [FromBody] EditUserDescriptionViewModel model)
        {
            if (model == null)
            {
                model = new EditUserDescriptionViewModel();
                Validate(model);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Find the user description by using id.
            var userDescriptions = _unitOfWork.UserDescriptions.Search();
            var userDescription  = await userDescriptions.FirstOrDefaultAsync(x => x.Id == id);

            // Find the first record.
            if (userDescription == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.UserDescriptionNotFoud)));
            }

            userDescription.Description = model.Description;

            // Save changes.
            await _unitOfWork.CommitAsync();

            return(Ok(userDescription));
        }
Пример #2
0
        public async Task <IHttpActionResult> EditUserDescription([FromUri] int id,
                                                                  [FromBody] EditUserDescriptionViewModel model)
        {
            if (model == null)
            {
                model = new EditUserDescriptionViewModel();
                Validate(model);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userdescription = await _userDesciptionDomain.EditUserDescriptionAsync(model);

            return(Ok(userdescription));
        }
Пример #3
0
        public async Task <UserDescription> EditUserDescriptionAsync(EditUserDescriptionViewModel model,
                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            // Find the user description by using id.
            var userDescription = await _dbContext.UserDescriptions.FindAsync(model.Id, cancellationToken);

            // Find the first record.
            if (userDescription == null)
            {
                throw new Exception();
            }

            userDescription.Description = model.Description;

            // Save changes.
            await _dbContext.SaveChangesAsync(cancellationToken);

            return(userDescription);
        }
        public async Task <IHttpActionResult> EditUserDescription([FromUri] int id,
                                                                  [FromBody] EditUserDescriptionViewModel model)
        {
            if (model == null)
            {
                model = new EditUserDescriptionViewModel();
                Validate(model);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userDescription =
                await _userDescriptionService.EditUserDescriptionAsync(id, model, CancellationToken.None);

            return(Ok(userDescription));
        }
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public virtual async Task <UserDescription> EditUserDescriptionAsync(int id, EditUserDescriptionViewModel model,
                                                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            // Find user description.
            var loadUserDescriptionCondition = new SearchUserDescriptionViewModel();

            loadUserDescriptionCondition.Ids = new HashSet <int>();
            loadUserDescriptionCondition.Ids.Add(id);

            // Get user description.
            var userDescription =
                await GetUserDescriptions(loadUserDescriptionCondition).FirstOrDefaultAsync(cancellationToken);

            if (userDescription == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, HttpMessages.UserDescriptionNotFoud);
            }

            userDescription.Description = model.Description;
            await _unitOfWork.CommitAsync();

            return(userDescription);
        }