Esempio n. 1
0
        public async Task <ResponseModel> UpdateBookCategoryAsync(Guid id, BookCategoryManageModel bookCategoryManageModel)
        {
            var bookCategory = await _repository.GetByIdAsync(id);

            if (bookCategory == null)
            {
                return(new ResponseModel()
                {
                    StatusCode = System.Net.HttpStatusCode.NotFound,
                    Message = "This bookCategory is not exist"
                });
            }
            else
            {
                var existedBookCategoryName = await _repository.FetchFirstAsync(x => x.Name == bookCategoryManageModel.Name && x.Id != id);

                if (existedBookCategoryName != null)
                {
                    return(new ResponseModel()
                    {
                        StatusCode = System.Net.HttpStatusCode.BadRequest,
                        Message = "BookCategory " + bookCategoryManageModel.Name + " is exist on system. Please try again!",
                    });
                }
                else
                {
                    bookCategoryManageModel.GetBookCategoryFromModel(bookCategory);
                    return(await _repository.UpdateAsync(bookCategory));
                }
            }
        }
Esempio n. 2
0
        public async Task <ResponseModel> CreateBookCategoryAsync(BookCategoryManageModel bookCategoryManageModel)
        {
            var bookCategory = await _repository.FetchFirstAsync(x => x.Name == bookCategoryManageModel.Name);

            if (bookCategory != null)
            {
                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.BadRequest,
                    Message = "This BookCategory is exist"
                });
            }
            else
            {
                bookCategory = new BookCategory();
                bookCategoryManageModel.GetBookCategoryFromModel(bookCategory);
                await _repository.InsertAsync(bookCategory);

                return(new ResponseModel
                {
                    StatusCode = System.Net.HttpStatusCode.OK,
                    Data = new BookCategoryViewModel(bookCategory),
                });
            }
        }