public async Task <IActionResult> Post([FromBody] OrderItemDto data)
        {
            APIResult apiResult;
            OrderItem record = mapper.Map <OrderItem>(data);

            if (record != null)
            {
                var result       = mapper.Map <OrderItemDto>(record);
                var isSuccessful = await OrderItemService.AddAsync(record);

                if (isSuccessful)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status201Created,
                                                       ErrorMessageEnum.None, payload: result);
                }
                else
                {
                    apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                       ErrorMessageEnum.無法新增紀錄, payload: result);
                }
            }
            else
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.傳送過來的資料有問題, payload: data);
            }
            return(Ok(apiResult));
        }
Esempio n. 2
0
        public async Task OnRecordEditConfirm()
        {
            #region 進行 Form Validation 檢查驗證作業
            if (LocalEditContext.Validate() == false)
            {
                return;
            }
            #endregion

            #region 檢查資料完整性
            if (isNewRecordMode == true)
            {
                var checkedResult = await CurrentService
                                    .BeforeAddCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    VerifyRecordResultHelper.GetMessageString(checkedResult), MessageBox.HiddenAsync);
                    thisView.NeedRefresh();
                    return;
                }
            }
            else
            {
                var checkedResult = await CurrentService
                                    .BeforeUpdateCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    VerifyRecordResultHelper.GetMessageString(checkedResult), MessageBox.HiddenAsync);
                    thisView.NeedRefresh();
                    return;
                }
            }
            #endregion

            if (IsShowEditRecord == true)
            {
                if (isNewRecordMode == true)
                {
                    var verifyRecordResult = await CurrentService.AddAsync(CurrentRecord);

                    await TranscationResultHelper.CheckDatabaseResult(MessageBox, verifyRecordResult);

                    dataGrid.RefreshGrid();
                }
                else
                {
                    var verifyRecordResult = await CurrentService.UpdateAsync(CurrentRecord);

                    await TranscationResultHelper.CheckDatabaseResult(MessageBox, verifyRecordResult);

                    dataGrid.RefreshGrid();
                }
                IsShowEditRecord = false;
            }
        }
Esempio n. 3
0
        public async Task OnRecordEditConfirm()
        {
            #region 進行 Form Validation 檢查驗證作業
            if (LocalEditContext.Validate() == false)
            {
                return;
            }
            #endregion

            #region 檢查資料完整性
            if (isNewRecordMode == true)
            {
                var checkedResult = await CurrentService
                                    .BeforeAddCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId));
                    thisView.NeedRefresh();
                    return;
                }
            }
            else
            {
                var checkedResult = await CurrentService
                                    .BeforeUpdateCheckAsync(CurrentRecord);

                if (checkedResult.Success == false)
                {
                    MessageBox.Show("400px", "200px", "警告",
                                    ErrorMessageMappingHelper.Instance.GetErrorMessage(checkedResult.MessageId));
                    thisView.NeedRefresh();
                    return;
                }
            }
            #endregion

            if (IsShowEditRecord == true)
            {
                if (isNewRecordMode == true)
                {
                    await CurrentService.AddAsync(CurrentRecord);

                    dataGrid.RefreshGrid();
                }
                else
                {
                    await CurrentService.UpdateAsync(CurrentRecord);

                    dataGrid.RefreshGrid();
                }
                IsShowEditRecord = false;
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([FromBody] OrderItemResource itemResource)
        {
            if (itemResource == null)
            {
                itemResource = new OrderItemResource();
            }

            var item = _mapper.Map <OrderItemResource, OrderItem>(itemResource);
            await _orderItemService.AddAsync(item);

            return(Ok());
        }
        public async Task OnRecordEditConfirm()
        {
            #region 進行 Form Validation 檢查驗證作業
            if (LocalEditContext.Validate() == false)
            {
                return;
            }
            #endregion

            #region 檢查資料完整性
            if (isNewRecordMode == true)
            {
                var checkedResult = await CurrentService
                                    .BeforeAddCheckAsync(mapper.Map <OrderItem>(CurrentRecord));

                if (checkedResult == false)
                {
                    ConfirmMessageBox.Show("400px", "200px", "警告", "該學生已經存在該課程內,無法完成新增");
                    return;
                }
            }
            else
            {
                var checkedResult = await CurrentService
                                    .BeforeUpdateCheckAsync(mapper.Map <OrderItem>(CurrentRecord));

                if (checkedResult == false)
                {
                    ConfirmMessageBox.Show("400px", "200px", "警告", "該學生已經存在該課程內,無法完成修改");
                    return;
                }
            }
            #endregion

            if (IsShowEditRecord == true)
            {
                if (isNewRecordMode == true)
                {
                    await CurrentService.AddAsync(mapper.Map <OrderItem>(CurrentRecord));

                    dataGrid.RefreshGrid();
                }
                else
                {
                    await CurrentService.UpdateAsync(mapper.Map <OrderItem>(CurrentRecord));

                    dataGrid.RefreshGrid();
                }
                IsShowEditRecord = false;
            }
        }
        public async Task <IActionResult> Post([FromBody] OrderItemDto data)
        {
            APIResult apiResult;

            #region 驗證 DTO 物件的資料一致性
            if (!ModelState.IsValid)
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.傳送過來的資料有問題, payload: data);
                return(Ok(apiResult));
            }
            #endregion

            OrderItemAdapterModel record = mapper.Map <OrderItemAdapterModel>(data);
            if (record != null)
            {
                var result = mapper.Map <OrderItemDto>(record);

                #region 新增記錄前的紀錄完整性檢查
                VerifyRecordResult verify = await OrderItemService.BeforeAddCheckAsync(record);

                if (verify.Success == false)
                {
                    apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                       ErrorMessageMappingHelper.Instance.GetErrorMessage(verify.MessageId),
                                                       payload: result);
                    return(Ok(apiResult));
                }
                #endregion

                var verifyRecordResult = await OrderItemService.AddAsync(record);

                if (verifyRecordResult.Success)
                {
                    apiResult = APIResultFactory.Build(true, StatusCodes.Status201Created,
                                                       ErrorMessageEnum.None, payload: null);
                }
                else
                {
                    apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                       verifyRecordResult.MessageId, payload: result);
                }
            }
            else
            {
                apiResult = APIResultFactory.Build(false, StatusCodes.Status200OK,
                                                   ErrorMessageEnum.傳送過來的資料有問題, payload: data);
            }
            return(Ok(apiResult));
        }
        public async Task <IHttpActionResult> AddOrderItem(OrderItemDto orderItemDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try {
                var orderItem = new OrderItem();
                orderItem.OrderId   = orderItemDto.OrderId;
                orderItem.ProductId = orderItemDto.ProductId;
                orderItem.Quantity  = orderItemDto.Quantity;

                var createdOrderItem = _orderItemService.AddAsync(orderItem);

                orderItemDto.Id = createdOrderItem.Id;
                return(CreatedAtRoute("ApiRoute", new { id = orderItemDto.Id }, orderItemDto));
            }
            catch (DbUpdateConcurrencyException)
            {
                //Log something here..
                return(InternalServerError());
            }
        }
        public async Task <ObjectResult> Post([FromBody] OrderItemInputResource inputOrderItem)
        {
            var response = await service.AddAsync(inputOrderItem);

            return(response.AsResource(mapper));
        }
Esempio n. 9
0
        public async Task <IActionResult> Save(OrderItemDto orderItemDto)
        {
            var orderItemSave = await _orderItemService.AddAsync(_mapper.Map <OrderItem>(orderItemDto));

            return(Created(string.Empty, _mapper.Map <OrderItemDto>(orderItemSave)));
        }