public async Task <IActionResult> Post([FromBody] SysUsersRequestDto dto) { if (dto == null) { return(Json(ApiJsonResult.ErrorResult("注册信息为空"))); } var validResult = new SysUsersValidator().Validate(dto); if (!validResult.IsValid) { string errorMsg = string.Join('\n', validResult.Errors.AsQueryable().Select(p => p.ErrorMessage).ToArray()); return(Json(ApiJsonResult.ErrorResult(errorMsg))); } if (_sysUserService.ExistEmail(dto.Email)) { return(Json(ApiJsonResult.ErrorResult("邮箱已注册"))); } var result = await _sysUserService.CreateAsync(dto); if (result) { return(Json(ApiJsonResult.SuccessResult("成功"))); } else { return(Json(ApiJsonResult.ErrorResult("失败"))); } }
public async Task <ApiJsonResult> Delete(int id) { var result = new ApiJsonResult(); var category = await GetById(id) .Include(p => p.ParentCategory) .Include(p => p.ProductCategories) .AsNoTracking() .FirstOrDefaultAsync(); if (category == null) { result.Code = CodeModel.Fail; result.Message = "Product Category is not found"; return(result); } if (category.ParentCategory != null || category.ProductCategories.Any()) { result.Code = CodeModel.Fail; result.Message = "CATEGORY_IN_USE"; return(result); } _unitOfWork.CategoryRepository.Delete(category); await _unitOfWork.Commit(); return(result); }
public async Task <IActionResult> Get([FromQuery] CategorySearchModel searchmodel) { const string loggerHeader = "GetCategorys -"; _logService.Info($"{loggerHeader} Start"); var result = new ApiJsonResult(); try { if (searchmodel.TypeSearch == (int)TypeSearchCategory.ByMenuCategory) { result.Data = await _CategoryService.GetMenuCategory(); } if (searchmodel.TypeSearch == (int)TypeSearchCategory.ByGetOneId) { result.Data = await _CategoryService.GetOneId(searchmodel.CategoryID); } } catch (Exception ex) { _logService.Error($"{loggerHeader} Throw error {ex.Message}"); result.Code = CodeModel.Fail; result.Message = ex.Message; } return(Ok(result)); }
public JsonResult DeploySmartContracts(DeployModel model) { var result = new ApiJsonResult(); try { using (var dbContext = new DatabaseContext()) { var networkIP = GetIP(model.Network); if (!string.IsNullOrEmpty(networkIP)) { if (string.IsNullOrEmpty(model.PublicKey) || string.IsNullOrEmpty(model.PrivateKey)) { var email = User?.Identity?.Name; var user = dbContext.Users.FirstOrDefault(x => x.Email == email); model.PublicKey = user?.PublicKey; model.PrivateKey = user?.PrivateKey; } using (Work work = new Work(networkIP)) { var transaction = work.Api.SendTransaction <CreateTransactionModel>(new CreateTransactionModel(new TransactionCreateModel { Amount = "0", Fee = "1", Source = model.PublicKey, Smart = new SmartCreateModel { Code = model.JavaCode } }), Base58Check.Base58CheckEncoding.DecodePlain(model.PrivateKey)); var source = Base58Check.Base58CheckEncoding.EncodePlain(transaction.Source); var target = Base58Check.Base58CheckEncoding.EncodePlain(transaction.Target); result.IsSuccess = true; result.Address = target; result.Message = "Ok!"; } } else { result.IsSuccess = false; result.Message = "Network is wrong."; } } } catch (Exception err) { result.IsSuccess = false; result.Message = "Error: " + err.Message; } return(new JsonResult { MaxJsonLength = Int32.MaxValue, Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public async Task <ApiJsonResult> Create(Customer data) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is not null"; return(result); } if (string.IsNullOrEmpty(data.PhoneNumber)) { result.Code = CodeModel.Fail; result.Message = "PhoneNumber is not null"; return(result); } var customer = _mapper.Map <Customer>(data); _unitOfWork.CustomerRepository.Create(customer); await _unitOfWork.Commit(); return(result); }
public async Task <ApiJsonResult> Create(int?tenantId, CustomerDto data) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is not null"; return(result); } if (string.IsNullOrEmpty(data.CustomerCode)) { result.Code = CodeModel.Fail; result.Message = "Customer Code is not null"; return(result); } if (await ValidateDuplicateCode(data.Id, data.CustomerCode)) { result.Code = CodeModel.Fail; result.Message = "Customer Code is duplicated"; return(result); } var customer = _mapper.Map <Customer>(data); customer.TenantId = tenantId.Value; customer.CustomerTypeId = CustomerType.Customer; _unitOfWork.CustomerRepository.Create(customer); await _unitOfWork.Commit(); return(result); }
public async Task <IActionResult> GetCustomers([FromQuery] int?customerId, [FromQuery] string customerCode) { const string loggerHeader = "GetCustomers -"; _logService.Info($"{loggerHeader} Start"); var result = new ApiJsonResult(); try { var userLogin = await _userService.GetCurrentUserLogin(HttpContext); _logService.Info($"{loggerHeader} with tenantId {userLogin?.TenantId}, customerId {customerId}, customerCode {customerCode}"); var customerFilter = new CustomerFilter { TenantId = userLogin.TenantId, CustomerId = customerId, CustomerCode = customerCode }; result.Data = await _customerService.GetByFilter(customerFilter); } catch (Exception ex) { _logService.Error($"{loggerHeader} Throw error {ex.Message}"); result.Code = CodeModel.Fail; result.Message = ex.Message; } return(Ok(result)); }
public async Task <ApiJsonResult> Update(UserLogin userLogin, CategoryDto data) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is null"; return(result); } var checkProduct = await GetById(data.Id.Value).AsNoTracking().FirstOrDefaultAsync(); if (checkProduct == null) { result.Code = CodeModel.Fail; result.Message = "Product Category is not found"; return(result); } if (await ValidateDuplicateName(data.Id, data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is duplicated"; return(result); } var category = _mapper.Map <Category>(data); category.TenantId = userLogin.TenantId.Value; category.UserModifiedId = userLogin.UserId; category.ModifiedDate = DateTime.Now; _unitOfWork.CategoryRepository.Update(category); await _unitOfWork.Commit(); return(result); }
public IHttpActionResult GetAllManufacturer() { List <Manufacturer> model = new List <Manufacturer>(); ApiJsonResult <List <Manufacturer> > lstManufacturer = new ApiJsonResult <List <Manufacturer> >(); string post = ""; if (ModelState.IsValid) { try { WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json"); string reStr = client.DownloadString(_ISetting.oms.Base_Url + "/api/product/GetAllManufacturer"); _ilog4netHelper.WriteLog_Info <ERP获取品牌列表>(post, null, null, "", "", null); _ilog4netHelper.WriteLog_Info <ERP获取品牌列表>(reStr, null, null, "", "", null); lstManufacturer = JsonConvert.DeserializeObject <ApiJsonResult <List <Manufacturer> > >(reStr); model = lstManufacturer.data; } catch (Exception ex) { _ilog4netHelper.WriteLog_Error <ERP获取品牌列表>(post, null, null, "", "", ex); } } else { _ilog4netHelper.WriteLog_Waring <ERP销售单位代码>(JsonConvert.SerializeObject(post), null, null, "", "", null); } return(Json(model)); }
public async Task <ApiJsonResult> GetByFilter(ProfitFilter profitFilter) { var result = new ApiJsonResult(); var profits = await _unitOfWork.OrderRepository .FindByCondition(o => o.TenantId == profitFilter.TenantId && (o.OrderType == OrderType.Order || o.OrderType == OrderType.Sale || o.OrderType == OrderType.ReturnSupplier)) .AsNoTracking() .ToListAsync(); switch (profitFilter.TurnoverType) { case ProfitType.Product: result.Data = await GetListByProduct(profits); break; case ProfitType.Store: result.Data = await GetListByStore(profits); break; case ProfitType.Time: result.Data = await GetListByTime(profits); break; default: break; } return(result); }
/// <summary> /// Add response (Unauthorized) when authenticate failed /// </summary> /// <returns></returns> private void HandleAuthorizeFailAsync(AuthorizationFilterContext context) { var unauthorized = new ApiJsonResult <object>((int)HttpCode.Unauthorized, HttpCode.Unauthorized.GetDescription()); context.HttpContext.Response.StatusCode = (int)HttpCode.Unauthorized; context.Result = new JsonResult(unauthorized); }
public void OnException(ExceptionContext context) { var logFactory = context.HttpContext.RequestServices.GetService <ILoggerFactory>(); _logger = logFactory.CreateLogger <MvcActionFilter>(); //财务回调api请求 var isFinanceApiCall = context.RouteData.Values.Any(g => string.Equals(g.Key, "fromApi", System.StringComparison.CurrentCultureIgnoreCase) && string.Equals(g.Value.ToString(), "finance", System.StringComparison.CurrentCultureIgnoreCase)); if (context.Exception is DomainException) { _logger.LogInformation(string.Format("调用【" + context.ActionDescriptor.DisplayName + "】发生了业务异常:{0}", context.Exception.Message)); if (isFinanceApiCall) { context.Result = ApiJsonResult.Fail(context.Exception.Message); } else if (context.HttpContext.Request.IsAjaxRequest()) { context.Result = new JsonResult(JsonResponse.CreateError(context.Exception)); } } else { _logger.LogError(new EventId(1), context.Exception, string.Format("调用" + context.ActionDescriptor.DisplayName + "出错:{0}\r\n{1}", context.Exception.Message, context.Exception.StackTrace)); if (isFinanceApiCall) { context.Result = ApiJsonResult.Fail("系统错误"); } else if (context.HttpContext.Request.IsAjaxRequest()) { context.Result = new JsonResult(JsonResponse.CreateError("系统错误")); } } }
public async Task <ApiJsonResult> Create(UserLogin userLogin, CategoryDto data) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is null"; return(result); } if (await ValidateDuplicateName(data.Id, data.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is duplicated"; return(result); } var category = _mapper.Map <Category>(data); category.TenantId = userLogin.TenantId.Value; category.CreatedDate = DateTime.Now; category.UserModifiedId = userLogin.UserId; _unitOfWork.CategoryRepository.Create(category); await _unitOfWork.Commit(); return(result); }
public async Task <IActionResult> GetMenus() { var result = new ApiJsonResult(); result.Data = _menuService.GetMenuByParent(); return(Ok(result)); }
public async Task <IActionResult> GetProducts([FromQuery] int?productId, [FromQuery] string name) { const string loggerHeader = "GetProducts -"; _logService.Info($"{loggerHeader} Start"); var result = new ApiJsonResult(); try { var userLogin = await _userService.GetCurrentUserLogin(HttpContext); _logService.Info($"{loggerHeader} Get products with tenantId {userLogin?.TenantId}, productId {productId}, name {name}"); var productFilter = new ProductFilter { TenantId = userLogin.TenantId, ProductId = productId, Name = name }; result.Data = await _productService.GetByFilter(productFilter); } catch (Exception ex) { _logService.Error($"{loggerHeader} Throw error {ex.Message}"); result.Code = CodeModel.Fail; result.Message = ex.Message; } return(Ok(result)); }
public async Task <ApiJsonResult> Create(int?tenantId, ProductDto productData) { var result = new ApiJsonResult(); if (string.IsNullOrEmpty(productData.Name)) { result.Code = CodeModel.Fail; result.Message = "Name is null"; return(result); } if (await ValidateDuplicateName(productData.Id, productData.Name)) { result.Code = CodeModel.Fail; result.Message = "Product name is duplicated"; return(result); } var product = _mapper.Map <Product>(productData); product.TenantId = tenantId.Value; if (string.IsNullOrEmpty(product.ProductCode)) { product.ProductCode = Constants.GenerateCode(); } _unitOfWork.ProductRepository.Create(product); await _unitOfWork.Commit(); return(result); }
public async Task <IActionResult> CreateCategory([FromBody] CategoryDto data) { const string loggerHeader = "CreateCategory -"; _logService.Info($"{loggerHeader} Start"); var result = new ApiJsonResult(); try { var userLogin = await _userService.GetCurrentUserLogin(HttpContext); _logService.Info($"{loggerHeader} Create category with tenantId {userLogin.TenantId}"); var user = new UserLogin { TenantId = userLogin.TenantId, UserId = userLogin.UserId }; result = await _categoryService.Create(user, data); } catch (Exception ex) { _logService.Error($"{loggerHeader} Throw error {ex.Message}"); result.Code = CodeModel.Fail; result.Message = ex.Message; } return(Ok(result)); }
public async Task <IActionResult> GetCategoriesAndSub([FromQuery] int?id) { const string loggerHeader = "GetCategoriesAndSub"; var result = new ApiJsonResult(); try { var userLogin = await _userService.GetCurrentUserLogin(HttpContext); _logService.Info($"{loggerHeader} Get product categories with tenantId {userLogin?.TenantId}"); var categoryFilter = new CategoryFilter { TenantId = userLogin?.TenantId, Id = id }; result.Data = await _categoryService.GetAllAndSub(categoryFilter); } catch (Exception ex) { result.Code = CodeModel.Fail; result.Message = ex.Message; } return(Ok(result)); }
public async Task <ApiJsonResult> Create(Order data) { var result = new ApiJsonResult(); var objOrder = new Order { Id = data.Id, Address = data.Address, CustomerName = data.CustomerName, Note = data.Note, PhoneNumber = data.PhoneNumber, OrderCode = Constants.GenerateCode(), Price = data.Price, TransportId = 1, CreatedDate = DateTime.Now }; _dbContext.Order.Add(objOrder); _dbContext.SaveChanges(); var test = objOrder.Id; foreach (var item in data.OrderItem) { var objOrderItem = new OrderItem { ProductId = item.ProductId, Number = item.Number, OrderId = objOrder.Id }; _dbContext.OrderItem.Add(objOrderItem); } _dbContext.SaveChanges(); return(result); }
public HttpResponseMessage UpdateExpress(ShipmentInfoViewModel value) { ApiJsonResult <object> message = new ApiJsonResult <object>(); string restr = ""; if (ModelState.IsValid) { try { _ilog4netHelper.WriteLog_Info <ERP发货确认>(JsonConvert.SerializeObject(value), null, "请求", value?.ClientGuid, value?.ClientName, null); string id = User.Identity.GetUserId(); if (string.IsNullOrEmpty(id) || _iUserRepository.GetClient(id, value.ClientGuid) == null) { message.msg = "用户名错误"; message.success = false; _ilog4netHelper.WriteLog_Error <ERP发货确认>(JsonConvert.SerializeObject(message), null, "3", value?.ClientGuid, value?.ClientName, null); restr = JsonConvert.SerializeObject(message); } else { WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json;charset=utf8"); IsoDateTimeConverter iso = new IsoDateTimeConverter(); iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; string update = JsonConvert.SerializeObject(value, iso); byte[] reByte_Api = client.UploadData(_ISetting.oms.Base_Url + "/api/order/delivery", "Post", Encoding.UTF8.GetBytes(update)); restr = Encoding.UTF8.GetString(reByte_Api); _ilog4netHelper.WriteLog_Info <ERP发货确认>(restr, null, "return", null); } } catch (Exception ex) { _ilog4netHelper.WriteLog_Error <ERP发货确认>(JsonConvert.SerializeObject(value), null, "2", value?.ClientGuid, value?.ClientName, ex); //api_message.MessageCode = ((int)m_Code.Faile).ToString(); message.success = false; message.msg = "oms连接错误"; restr = JsonConvert.SerializeObject(message); } } else { var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Keys) { returestr += "Key:" + item + "value:" + (modelstate.ModelState?[item].Errors != null ? (modelstate.ModelState?[item].Errors?[0].ErrorMessage + " " + modelstate.ModelState?[item].Errors?[0].Exception?.Message) : "");// item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; } //api_message.ErrorMsg = returestr; //api_message.MessageCode = ((int)m_Code.Faile).ToString(); message.msg = returestr; message.success = false; restr = JsonConvert.SerializeObject(message); _ilog4netHelper.WriteLog_Error <ERP发货确认>(JsonConvert.SerializeObject(value), null, "3", value?.ClientGuid, value?.ClientName, null); _ilog4netHelper.WriteLog_Error <ERP发货确认>(JsonConvert.SerializeObject(message), "4", null, value?.ClientGuid, value?.ClientName, null); } return(new HttpResponseMessage { Content = new StringContent(restr, Encoding.UTF8) }); }
public async Task <IActionResult> GetMenus() { var result = new ApiJsonResult(); var menuFileter = new MenuFilter(); result.Data = await _menuService.GetMenusByUserRoles(menuFileter); return(Ok(result)); }
public IHttpActionResult stockupdate([FromBody] StockViewModel value) { StockViewModel model = new StockViewModel(); ApiJsonResult re = new ApiJsonResult(); string post = ""; if (ModelState.IsValid) { try { post = JsonConvert.SerializeObject(value); _ilog4netHelper.WriteLog_Info <ERP库存更新>(post, null, null, value?.ClientGuid, value?.ClientName, null); string id = User.Identity.GetUserId(); if (string.IsNullOrEmpty(id) || _iUserRepository.GetClient(id, value.ClientGuid) == null) { re.data = "用户名错误"; return(Json(re)); } WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json"); byte[] reByte = client.UploadData(_ISetting.oms.Base_Url + "/api/stock/receiveasaerpstock", Encoding.UTF8.GetBytes(post));//http://192.0.1.188:15536/api/vendor/receivevendor string reStr = Encoding.UTF8.GetString(reByte); _ilog4netHelper.WriteLog_Info <ERP库存更新>(post, null, null, value?.ClientGuid, value?.ClientName, null); _ilog4netHelper.WriteLog_Info <ERP库存更新>(reStr, null, null, value?.ClientGuid, value?.ClientName, null); re = JsonConvert.DeserializeObject <ApiJsonResult>(reStr); } catch (Exception ex) { _ilog4netHelper.WriteLog_Error <ERP库存更新>(post, null, null, value?.ClientGuid, value?.ClientName, ex); } } else { re.code = 0; re.msg = "ERP库存更新数据格式错误"; var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Keys) { //item. //item.Value.Value.RawValue.ToString() //returestr += item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; returestr += "Key:" + item + "value:" + (modelstate.ModelState?[item].Errors != null ? (modelstate.ModelState?[item].Errors?[0].ErrorMessage + " " + modelstate.ModelState?[item].Errors?[0].Exception?.Message) : "");// item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; } //foreach (var item in modelstate.ModelState.Keys) //{ // //item. // //item.Value.Value.RawValue.ToString() // returestr += item != null ? item.ToString() + "\r\n" : ""; //} re.success = false; re.data = returestr; _ilog4netHelper.WriteLog_Waring <ERP库存更新>(JsonConvert.SerializeObject(re), null, null, value?.ClientGuid?.ToString(), value.ClientName, null); } return(Json(re)); }
public HttpResponseMessage PlanceOrder(OutOrderViewModel value) { ApiJsonResult <object> message = new ApiJsonResult <object>(); string restr = ""; if (ModelState.IsValid) { try { _ilog4netHelper.WriteLog_Info <OMS向第三方ERP下单>(JsonConvert.SerializeObject(value), null, "请求", value?.ClientGuid, null, null); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json"); IsoDateTimeConverter iso = new IsoDateTimeConverter(); iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; string update = JsonConvert.SerializeObject(value, iso); string url = _ISetting.erp.kvs.Where(t => t.k == value.ClientGuid).FirstOrDefault().v; if (string.IsNullOrEmpty(url)) { message.success = false; message.code = 200; message.msg = "未查询到指定的供应商erp地址"; return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8) }); } byte[] reByte_Api = client.UploadData(url + "/api/order", "Post", Encoding.UTF8.GetBytes(update)); restr = Encoding.UTF8.GetString(reByte_Api); _ilog4netHelper.WriteLog_Info <OMS向第三方ERP下单>(restr, null, "return", null); } catch (Exception ex) { _ilog4netHelper.WriteLog_Error <OMS向第三方ERP下单>(JsonConvert.SerializeObject(value), null, "2", value?.ClientGuid, null, ex); //api_message.MessageCode = ((int)m_Code.Faile).ToString(); message.success = false; message.msg = "查询到指定的供应商erp地址连接错误"; restr = JsonConvert.SerializeObject(message); } } else { var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Keys) { returestr += "Key:" + item + "value:" + (modelstate.ModelState?[item].Errors != null ? (modelstate.ModelState?[item].Errors?[0].ErrorMessage + " " + modelstate.ModelState?[item].Errors?[0].Exception?.Message) : "");// item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; } message.msg = returestr; message.success = false; restr = JsonConvert.SerializeObject(message); _ilog4netHelper.WriteLog_Error <OMS向第三方ERP下单>(JsonConvert.SerializeObject(value), null, "3", value?.ClientGuid, null, null); _ilog4netHelper.WriteLog_Error <OMS向第三方ERP下单>(JsonConvert.SerializeObject(message), "4", null, value?.ClientGuid, null, null); } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8) }); }
public async Task <IActionResult> Logout() { var userLogin = await _userService.GetCurrentUserLogin(HttpContext); var result = new ApiJsonResult(); await _loginService.Logout(_mapper.Map <UserLogin>(userLogin)); HttpContext.User = null; return(Ok(result)); }
public async Task <IActionResult> Login([FromBody] UserDto userDto) { var userLogin = await _loginService.Login(userDto.Username, userDto.Password); var result = new ApiJsonResult(); if (userLogin == null) { result.Code = CodeModel.Fail; return(BadRequest(result)); } result.Data = userLogin; return(Ok(result)); }
public async Task <ApiJsonResult> Delete(int?tenantId, long userId, int id) { var result = new ApiJsonResult(); var order = await GetById(id).AsNoTracking().FirstOrDefaultAsync(); if (order == null) { result.Code = CodeModel.Fail; result.Message = "Order is not found"; return(result); } var orderNoteModel = await _unitOfWork.OrderNoteRepository .FindByCondition(on => on.OrderId == order.Id) .FirstOrDefaultAsync(); if (orderNoteModel != null) { _unitOfWork.OrderNoteRepository.Delete(orderNoteModel); } var orderItemModels = await _unitOfWork.OrderItemRepository .FindByCondition(oi => oi.OrderId == order.Id) .AsNoTracking() .ToListAsync(); if (orderItemModels.Any()) { _unitOfWork.OrderItemRepository.RemoveRange(orderItemModels); } var shipmentModel = await _unitOfWork.ShipmentRepository .FindByCondition(s => s.OrderId == order.Id) .AsNoTracking() .FirstOrDefaultAsync(); if (shipmentModel != null) { _unitOfWork.ShipmentRepository.Delete(shipmentModel); } _unitOfWork.OrderRepository.Delete(order); await _unitOfWork.Commit(); var userModified = new UserModified { TenantId = tenantId, UserId = userId }; return(result); }
private void HandleFailResult(HttpCode httpCode) { var response = _httpContextAccessor.HttpContext.Response; var content = new ApiJsonResult <object>((int)httpCode, httpCode.GetDescription()); var message = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(content, new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, })); response.OnStarting(async() => { response.StatusCode = (int)httpCode; response.ContentType = HeaderMediaType.JSON.GetDescription(); await response.Body.WriteAsync(message, 0, message.Length); }); }
public async Task <ApiJsonResult> Delete(int id) { var result = new ApiJsonResult(); var customer = await GetById(id).AsNoTracking().FirstOrDefaultAsync(); if (customer == null) { result.Code = CodeModel.Fail; result.Message = "Customer is not found"; return(result); } _unitOfWork.CustomerRepository.Delete(customer); await _unitOfWork.Commit(); return(result); }
public async Task <ApiJsonResult> Delete(int id) { var result = new ApiJsonResult(); var balance = await _unitOfWork.BalanceRepository.FindByCondition(b => b.Id == id) .AsNoTracking().FirstOrDefaultAsync(); if (balance == null) { result.Code = CodeModel.Fail; result.Message = "Balance is not found"; return(result); } _unitOfWork.BalanceRepository.Delete(balance); await _unitOfWork.Commit(); return(result); }
public HttpResponseMessage EcmallCreateWish([FromBody] EcmallRefundsOrderViewModel value) { string reStr = ""; ApiJsonResult <object> message = new ApiJsonResult <object>(); try { if (ModelState.IsValid) { message.success = true; message.code = 200; string post = JsonConvert.SerializeObject(value); WebClient client = new WebClient(); client.Headers.Add("Content-Type", "application/json"); byte[] reByte = client.UploadData(_ISetting.oms.Base_Url + "/API/Order/CreateWish", Encoding.UTF8.GetBytes(post)); reStr = Encoding.UTF8.GetString(reByte); //message = JsonConvert.DeserializeObject<ApiJsonResult<object>>(reStr); _logger.WriteLog_Info <Ecmall顾客退款>(reStr, null, "ecmall返回", null); _logger.WriteLog_Info <Ecmall顾客退款>(JsonConvert.SerializeObject(value), null, null, null); } else { var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Values) { returestr += item.Errors != null ? item.Errors[0].ErrorMessage + " \r\n" : ""; } message.msg = returestr; message.success = false;// m_Code.Faile.ToString(); reStr = JsonConvert.SerializeObject(message); _logger.WriteLog_Error <Ecmall顾客退款>(JsonConvert.SerializeObject(value), null, null, null); _logger.WriteLog_Error <Ecmall顾客退款>(JsonConvert.SerializeObject(message), null, null, null); } } catch (Exception ex) { message.success = false; message.msg = ex.Message.ToString() + "oms连接错误"; reStr = JsonConvert.SerializeObject(message); _logger.WriteLog_Error <Ecmall顾客退款>(JsonConvert.SerializeObject(message), null, null, ex); } return(new HttpResponseMessage { Content = new StringContent(reStr, Encoding.UTF8) }); }