public async Task <bool> DeleteSupplierTopClientAsync(cor_topclient model)
        {
            var item = await _dataContext.cor_topclient.FindAsync(model.TopClientId);

            item.Deleted = true;
            _dataContext.Entry(item).CurrentValues.SetValues(model);
            return(await _dataContext.SaveChangesAsync() > 0);
        }
        public async Task <bool> UpdateSupplierTopClientAsync(cor_topclient model)
        {
            if (model.TopClientId > 0)
            {
                var itemTUpdate = await _dataContext.cor_topclient.FindAsync(model.TopClientId);

                if (itemTUpdate != null)
                {
                    _dataContext.Entry(itemTUpdate).CurrentValues.SetValues(model);
                }
            }
            else
            {
                await _dataContext.AddAsync(model);
            }
            return(await _dataContext.SaveChangesAsync() > 0);
        }
示例#3
0
        public async Task <SupplierTopClientRegRespObj> Handle(UpdateSupplierTopClientCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var currentUserId = _httpContextAccessor.HttpContext.User?.FindFirst(x => x.Type == "userId").Value;
                var user          = await _serverRequest.UserDataAsync();

                cor_topclient supTopClient = new cor_topclient();
                supTopClient.Deleted       = false;
                supTopClient.CreatedOn     = request.SupplierId > 0 ? (DateTime?)null : DateTime.Now;
                supTopClient.CreatedBy     = user != null ? user.UserName : "";
                supTopClient.UpdatedBy     = user != null ? user.UserName : "";
                supTopClient.Address       = request.Address;
                supTopClient.ContactPerson = request.ContactPerson;
                supTopClient.CreatedBy     = request.CreatedBy;
                supTopClient.CreatedOn     = DateTime.Today;
                supTopClient.Email         = request.Email;
                supTopClient.Name          = request.Name;
                supTopClient.NoOfStaff     = request.NoOfStaff;
                supTopClient.PhoneNo       = request.PhoneNo;
                supTopClient.SupplierId    = request.SupplierId;
                supTopClient.TopClientId   = request.TopClientId;
                supTopClient.CountryId     = request.CountryId;

                await _supRepo.UpdateSupplierTopClientAsync(supTopClient);

                return(new SupplierTopClientRegRespObj
                {
                    TopClientId = supTopClient.TopClientId,
                    Status = new APIResponseStatus
                    {
                        IsSuccessful = true,
                        Message = new APIResponseMessage
                        {
                            FriendlyMessage = "Successful",
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                #region Log error to file
                var errorCode = ErrorID.Generate(4);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new SupplierTopClientRegRespObj
                {
                    Status = new APIResponseStatus
                    {
                        IsSuccessful = false,
                        Message = new APIResponseMessage
                        {
                            FriendlyMessage = "Error occured!! Unable to process item",
                            MessageId = errorCode,
                            TechnicalMessage = $"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}"
                        }
                    }
                });

                #endregion
            }
        }