コード例 #1
0
        public async Task <ActionResult <AccountTypeRegRespObj> > AddUpDateAccountType([FromBody] AddUpdateAccountTypeObj model)
        {
            try
            {
                var user = await _identityServer.UserDataAsync();

                deposit_accountype item = null;
                if (model.AccountTypeId > 0)
                {
                    item = await _repo.GetAccountTypeByIdAsync(model.AccountTypeId);

                    if (item == null)
                    {
                        return new AccountTypeRegRespObj
                               {
                                   Status = new APIResponseStatus {
                                       IsSuccessful = false, Message = new APIResponseMessage {
                                           FriendlyMessage = "Item does not Exist"
                                       }
                                   }
                               }
                    }
                    ;
                }

                var domainObj = new deposit_accountype();
                domainObj.AccountTypeId = model.AccountTypeId > 0 ? model.AccountTypeId : 0;
                domainObj.Active        = true;
                domainObj.CreatedBy     = user.UserName;
                domainObj.CreatedOn     = DateTime.Today;
                domainObj.Deleted       = false;
                domainObj.Description   = model.Description;
                domainObj.Name          = model.Name;
                domainObj.UpdatedBy     = user.UserName;
                domainObj.UpdatedOn     = model.AccountTypeId > 0 ? DateTime.Today : DateTime.Today;

                var isDone = await _repo.AddUpdateAccountTypeAsync(domainObj);

                return(new AccountTypeRegRespObj
                {
                    AccountTypeId = domainObj.AccountTypeId,
                    Status = new APIResponseStatus {
                        IsSuccessful = isDone ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = isDone ? "successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new AccountTypeRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }