Exemple #1
0
        public async Task <IActionResult> Update([FromBody] Categories inputModel)
        {
            try
            {
                if (string.IsNullOrEmpty(inputModel.Name))
                {
                    throw new Exception($"Tên chuyên mục {MessageConst.NOT_EMPTY_INPUT}");
                }
                var data = await _categoryManager.FindByIdUpdate(inputModel.Id);

                if (data == null)
                {
                    throw new Exception(MessageConst.DATA_NOT_FOUND);
                }
                //var dataDisplay = await _categoryManager.CheckDisplayOrder(inputModel.DisplayOrder);
                //if (dataDisplay != null && dataDisplay.Id != inputModel.Id)
                //{
                //    throw new Exception($"Thứ tự hiển thị đã dùng chuyên mục khác");
                //}
                inputModel.Code        = inputModel.Code.Trim().Replace(" ", "");
                inputModel.CreatedDate = data.CreatedDate;
                inputModel.UpdatedDate = DateTime.Now;
                await _categoryManager.Update(inputModel);

                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }