Пример #1
0
        private ApiResponse Update(int id, UpdateCustomerViewModel model)
        {
            var apiResp = new ApiResponse
            {
                Type = ResponseType.Fail
            };

            var customer = new Dto.Customer
            {
                Id = id,
                AuthorizedPersonName = model.AuthorizedPersonName,
                PhoneNumber          = model.PhoneNumber,
                Title  = model.Title,
                UserId = GetUserId().Value
            };

            _customerBusiness.OwnerId = customer.UserId;

            var resp = _customerBusiness.Edit(customer);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            apiResp.Type = ResponseType.Success;
            return(apiResp);
        }
Пример #2
0
        private ApiResponse <int> Create(CreateCustomerViewModel model)
        {
            var apiResp = new ApiResponse <int>
            {
                Type = ResponseType.Fail
            };

            var customer = new Dto.Customer
            {
                AuthorizedPersonName = model.AuthorizedPersonName,
                PhoneNumber          = model.PhoneNumber,
                Title     = model.Title,
                UserId    = GetUserId().Value,
                CreatedAt = DateTime.UtcNow
            };

            var resp = _customerBusiness.Add(customer);

            if (resp.Type != ResponseType.Success)
            {
                apiResp.ErrorCode = resp.ErrorCode;
                return(apiResp);
            }

            apiResp.Type = ResponseType.Success;
            apiResp.Data = customer.Id;

            return(apiResp);
        }
 private void SetCustomerBalance(Dto.Customer customer, bool isDebt, double amount)
 {
     if (isDebt)
     {
         customer.DebtBalance += amount;
     }
     else
     {
         customer.ReceivableBalance += amount;
     }
 }
Пример #4
0
        public static Dto.Customer ConvertToDto(this Model.Customer customer)
        {
            Dto.Customer customerDto = new Dto.Customer
            {
                Id          = customer.Id,
                SecurityKey = customer.SecurityKey,
                Name        = customer.Name,
                EditionId   = customer.EditionId,
                Enabled     = customer.Enabled,
            };

            return(customerDto);
        }
Пример #5
0
        public static Model.Customer ConvertToEntity(this Dto.Customer customerDto, Model.Customer customer = null)
        {
            if (customer == null)
            {
                customer = new Model.Customer();
            }

            customer.Id          = customerDto.Id;
            customer.Name        = customerDto.Name;
            customer.Enabled     = customerDto.Enabled;
            customer.EditionId   = customerDto.EditionId;
            customer.SecurityKey = customerDto.SecurityKey;


            return(customer);
        }