Beispiel #1
0
        /// <summary>
        /// Переводит информацию для редактирования коллекции из клиентской модели в серверную
        /// </summary>
        /// <param name="viewCollection">Тренировка в клиентской модели</param>
        /// <returns>Тренировка в серверной модели</returns>
        public static Model.CardsCollectionPatchInfo ConvertPatchInfo(View.CardsCollectionPatchInfo viewCollection)
        {
            var collection = new Model.CardsCollectionPatchInfo
            {
                Name = viewCollection.Name
            };

            return(collection);
        }
        public async Task <IActionResult> UpdateCardByIdAsync(string collectionName,
                                                              [FromBody] View.CardsCollectionPatchInfo updateInfo, CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var userId);

                if (!await collectionService.IsNameExistAsync(collectionName, userId))
                {
                    return(BadRequest(new { message = "No collection with name \"" + collectionName + "\"" }));
                }

                var collection = CardsCollectionConverter.ConvertPatchInfo(updateInfo);
                collectionService.UpdateByIdAsync(collection, collectionName, userId);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> UpdateCardByIdAsync(string id,
                                                              [FromBody] View.CardsCollectionPatchInfo updateInfo, CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var userId);
                Guid.TryParse(id, out var collectionId);

                if (!await collectionService.IsIdExistAsync(collectionId, userId))
                {
                    return(BadRequest(new { message = "Нет коллекции с указанным идентификатором" }));
                }

                var collection = CardsCollectionConverter.ConvertPatchInfo(updateInfo);
                collectionService.UpdateByIdAsync(collection, collectionId, userId);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }