示例#1
0
        public async Task <IHttpActionResult> RegisterClient([FromBody] ClientInfo clientInfo)
        {
            Requires.NotNull(clientInfo, nameof(clientInfo));

            var userName = clientInfo.CredentialInfo.UserName;

            IdentityResult result;
            var            user = new ApplicationUser
            {
                UserName = userName,
                Email    = userName + "@fake.com"
            };

            using (var userManager = Request.GetOwinContext().GetUserManager <ApplicationUserManager>())
            {
                result = await userManager.CreateAsync(user, clientInfo.CredentialInfo.Password);
            }

            if (!result.Succeeded)
            {
                return(BadRequest());
            }

            _repository.Add(clientInfo);

            return(Ok());
        }
示例#2
0
        public IActionResult AddOrder([FromBody] OrderInfoView orderInfoView)
        {
            var userId = CurrentUser.Id;

            if (string.IsNullOrEmpty(orderInfoView.ClientName))
            {
                return(JsonError("客户信息未填写"));
            }
            orderInfoView.ClientName = orderInfoView.ClientName.Trim();
            if (orderInfoView.ClientId == null)
            {
                var clientModel = _clientInfoRepository.FindBy(e => e.UserId == userId && e.ClientName == orderInfoView.ClientName && e.IsDel == 0);

                if (clientModel.Any())
                {
                    return(JsonError("该客户信息已存在,请直接选择"));
                }
                else
                {
                    ClientInfo clientInfo = new ClientInfo()
                    {
                        ClientName = orderInfoView.ClientName,
                        UserId     = userId,
                        IsDel      = 0,
                        CreateTime = DateTime.Now,
                        UpdateTime = DateTime.Now
                    };

                    var clientId = _clientInfoRepository.Add(clientInfo);
                    orderInfoView.ClientId = clientId;
                }
            }

            try
            {
                orderInfoView.UserId = userId;
                _orderInfoRepository.AddOrder(orderInfoView);
                return(JsonOk(""));
            }
            catch (Exception e)
            {
                return(JsonError(e.Message));
            }
        }
        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IActionResult Add([FromBody] ClientInfo model)
        {
            try
            {
                if (_clientInfoRepository.Count(e => e.ClientName == model.ClientName && e.UserId == CurrentUser.Id && e.IsDel == 0) > 0)
                {
                    return(JsonError("客户名重复"));
                }

                model.IsDel      = 0;
                model.CreateTime = DateTime.Now;
                model.UserId     = CurrentUser.Id;
                model.UpdateTime = DateTime.Now;

                _clientInfoRepository.Add(model);
                return(JsonOk(""));
            }
            catch (Exception ex)
            {
                return(JsonError(ex.Message));
            }
        }
示例#4
0
 public void CreateClientInfo(ClientInfo clientInfo)
 {
     _iClientInfoRepository.Add(clientInfo);
     Save();
 }