public async Task <ActionResult> ReadListAsync([FromQuery] SalesOrder_ReadListInput_Criteria _criteria) { ActionResult response; try { if (ModelState.IsValid) { Output <ICollection <SalesOrder_ReadListOutput> > output = await svc.ReadListAsync(_criteria); response = StatusCode((int)output.HttpStatus, output); return(response); } else { currentErrors.AddModelErrors(ModelState); } } catch (Exception ex) { currentErrors.MergeWith(errorsParser.FromException(ex)); } response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors)); return(response); }
public override bool Search(bool preserveSelection) { criteria.Validate(true); ErrorList valErr = criteria.GetValidationErrors(); errors.List.DataSource = valErr.Errors; errors.List.DataBind(); if (valErr.HasErrors()) { return(false); } ISalesOrderService svcSalesOrder = DI.Resolve <ISalesOrderService>(); try { SalesOrder_ReadListInput_Criteria inReadList_Criteria = new SalesOrder_ReadListInput_Criteria(); criteria.ToDataContract(inReadList_Criteria); IEnumerable <SalesOrder_ReadListOutput> outReadList; using (TimeTracker.ServiceCall) outReadList = svcSalesOrder.ReadList(inReadList_Criteria); list.FromDataContract(outReadList, preserveSelection); list.AppliedCriteria = criteria.GetFieldCriteriaSettings(); uclAppliedCriteria.BindTo(list.AppliedCriteria); return(true); } catch (Exception ex) { errors.List.DataSource = ErrorList.FromException(ex).Errors; errors.List.DataBind(); } finally { if (svcSalesOrder is IDisposable) { ((IDisposable)svcSalesOrder).Dispose(); } } return(false); }
protected virtual async Task <Output <ICollection <SalesOrder_ReadListOutput> > > SalesOrder_ReadListAsync(object options, SalesOrder_ReadListInput_Criteria _criteria) { using (var s = ServiceProvider.CreateScope()) { var output = await s.ServiceProvider.GetService <ISalesOrderService>().ReadListAsync(_criteria); await FromDataContractAsync(output?.Result, options); return(output); } }
public virtual async Task <Output <ICollection <SalesOrder_ReadListOutput> > > ReadListAsync(SalesOrder_ReadListInput_Criteria _criteria) { ICollection <SalesOrder_ReadListOutput> res = null; try { currentErrors.AbortIfHasErrors(); // CUSTOM_CODE_START: add custom security checks for ReadList operation below if (!CurrentPrincipal.IsEmployee() && !CurrentPrincipal.IsIndividualCustomer() && !CurrentPrincipal.IsStoreContact()) { currentErrors.CriticalError(ErrorType.Security, Messages.OperationNotAllowed); } // CUSTOM_CODE_END var src = from obj in ctx.SalesOrder select obj; // Source filter if (_criteria != null) { // CUSTOM_CODE_START: add code for GlobalRegion criteria of ReadList operation below src = AddClause(src, "GlobalRegion", o => o.TerritoryObject.Group, Operators.IsEqualTo, _criteria.GlobalRegion); // CUSTOM_CODE_END } // CUSTOM_CODE_START: add custom filter criteria to the source query for ReadList operation below if (CurrentPrincipal.IsStoreContact()) { int?storeId = CurrentPrincipal.GetStoreId(); src = src.Where(o => o.CustomerObject.StoreObject.BusinessEntityId == storeId); } if (CurrentPrincipal.IsIndividualCustomer()) { int?personId = CurrentPrincipal.GetPersonId(); src = src.Where(o => o.CustomerObject.PersonObject.BusinessEntityId == personId); } // CUSTOM_CODE_END var qry = from obj in src select new SalesOrder_ReadListOutput() { SalesOrderId = obj.SalesOrderId, SalesOrderNumber = obj.SalesOrderNumber, Status = obj.Status, OrderDate = obj.OrderDate, ShipDate = obj.ShipDate, DueDate = obj.DueDate, TotalDue = obj.TotalDue, OnlineOrderFlag = obj.OnlineOrderFlag, // CUSTOM_CODE_START: set the CustomerStore output parameter of ReadList operation below CustomerStore = obj.CustomerObject.StoreObject.Name, // CUSTOM_CODE_END // CUSTOM_CODE_START: set the CustomerName output parameter of ReadList operation below CustomerName = obj.CustomerObject.PersonObject.LastName + ", " + obj.CustomerObject.PersonObject.FirstName, // CUSTOM_CODE_END SalesPersonId = obj.SalesPersonId, TerritoryId = obj.TerritoryId, }; // Result filter if (_criteria != null) { qry = AddClause(qry, "SalesOrderNumber", o => o.SalesOrderNumber, _criteria.SalesOrderNumberOperator, _criteria.SalesOrderNumber); qry = AddClause(qry, "Status", o => o.Status, _criteria.StatusOperator, _criteria.Status); qry = AddClause(qry, "OrderDate", o => o.OrderDate, _criteria.OrderDateOperator, _criteria.OrderDate, _criteria.OrderDate2); qry = AddClause(qry, "DueDate", o => o.DueDate, _criteria.DueDateOperator, _criteria.DueDate, _criteria.DueDate2); qry = AddClause(qry, "TotalDue", o => o.TotalDue, _criteria.TotalDueOperator, _criteria.TotalDue, _criteria.TotalDue2); qry = AddClause(qry, "CustomerStore", o => o.CustomerStore, _criteria.CustomerStoreOperator, _criteria.CustomerStore); qry = AddClause(qry, "CustomerName", o => o.CustomerName, _criteria.CustomerNameOperator, _criteria.CustomerName); qry = AddClause(qry, "TerritoryId", o => o.TerritoryId, _criteria.TerritoryIdOperator, _criteria.TerritoryId); qry = AddClause(qry, "SalesPersonId", o => o.SalesPersonId, _criteria.SalesPersonIdOperator, _criteria.SalesPersonId); } // CUSTOM_CODE_START: add custom filter criteria to the result query for ReadList operation below // qry = qry.Where(o => o.FieldName == VALUE); // CUSTOM_CODE_END currentErrors.AbortIfHasErrors(); res = await qry.ToListAsync(); } catch (Exception ex) { currentErrors.MergeWith(errorParser.FromException(ex)); } return(await Task.FromResult(new Output <ICollection <SalesOrder_ReadListOutput> >(currentErrors, res))); }
protected virtual Output <ICollection <SalesOrder_ReadListOutput> > SalesOrder_ReadList(SalesOrder_ReadListInput_Criteria _criteria, object options) { using (var s = ServiceProvider.CreateScope()) { var output = s.ServiceProvider.GetService <ISalesOrderService>().ReadList(_criteria); FromDataContract(output?.Result, options); return(output); } }
public virtual IEnumerable <SalesOrder_ReadListOutput> ReadList(SalesOrder_ReadListInput_Criteria _criteria) { IEnumerable <SalesOrder_ReadListOutput> res = null; using (AdventureWorksEntities ctx = new AdventureWorksEntities()) { var src = from obj in ctx.SalesOrder select obj; #region Source filter if (_criteria != null) { // CUSTOM_CODE_START: add code for GlobalRegion criteria of ReadList operation below if (_criteria.GlobalRegion != null) { src = src.Where(o => _criteria.GlobalRegion == o.TerritoryIdObject.Group); } // CUSTOM_CODE_END } // CUSTOM_CODE_START: add custom filter criteria to the source query for ReadList operation below // src = src.Where(o => o.FieldName == VALUE); // CUSTOM_CODE_END #endregion var qry = from obj in src select new SalesOrder_ReadListOutput() { SalesOrderId = obj.SalesOrderId, SalesOrderNumber = obj.SalesOrderNumber, Status = obj.Status, OrderDate = obj.OrderDate, ShipDate = obj.ShipDate, DueDate = obj.DueDate, TotalDue = obj.TotalDue, OnlineOrderFlag = obj.OnlineOrderFlag, // CUSTOM_CODE_START: set the CustomerStore output parameter of ReadList operation below CustomerStore = obj.CustomerIdObject.StoreIdObject.Name, // CUSTOM_CODE_END // CUSTOM_CODE_START: set the CustomerName output parameter of ReadList operation below CustomerName = obj.CustomerIdObject.PersonIdObject.LastName + ", " + obj.CustomerIdObject.PersonIdObject.FirstName, // CUSTOM_CODE_END SalesPersonId = obj.SalesPersonIdObject.BusinessEntityId, TerritoryId = obj.TerritoryIdObject.TerritoryId, }; #region Result filter if (_criteria != null) { #region SalesOrderNumber if (_criteria.SalesOrderNumberOperator != null) { switch (_criteria.SalesOrderNumberOperator) { case Operators.IsEqualTo: qry = qry.Where(o => o.SalesOrderNumber == _criteria.SalesOrderNumber); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.SalesOrderNumber != _criteria.SalesOrderNumber); break; case Operators.Contains: qry = qry.Where(o => o.SalesOrderNumber.Contains(_criteria.SalesOrderNumber)); break; case Operators.DoesNotContain: qry = qry.Where(o => !o.SalesOrderNumber.Contains(_criteria.SalesOrderNumber)); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Sales Order Number.", _criteria.SalesOrderNumberOperator); break; } } #endregion #region Status if (_criteria.StatusOperator != null) { switch (_criteria.StatusOperator) { case Operators.IsEqualTo: qry = qry.Where(o => o.Status == _criteria.Status); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.Status != _criteria.Status); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Status.", _criteria.StatusOperator); break; } } #endregion #region OrderDate if (_criteria.OrderDateOperator != null) { switch (_criteria.OrderDateOperator) { case Operators.IsEqualTo: qry = qry.Where(o => o.OrderDate == _criteria.OrderDate); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.OrderDate != _criteria.OrderDate); break; case Operators.IsEarlierThan: qry = qry.Where(o => o.OrderDate < _criteria.OrderDate); break; case Operators.IsLaterThan: qry = qry.Where(o => o.OrderDate > _criteria.OrderDate); break; case Operators.IsBetween: qry = qry.Where(o => o.OrderDate >= _criteria.OrderDate && o.OrderDate <= _criteria.OrderDate2); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Order Date.", _criteria.OrderDateOperator); break; } } #endregion #region DueDate if (_criteria.DueDateOperator != null) { switch (_criteria.DueDateOperator) { case Operators.IsEqualTo: qry = qry.Where(o => o.DueDate == _criteria.DueDate); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.DueDate != _criteria.DueDate); break; case Operators.IsEarlierThan: qry = qry.Where(o => o.DueDate < _criteria.DueDate); break; case Operators.IsLaterThan: qry = qry.Where(o => o.DueDate > _criteria.DueDate); break; case Operators.IsBetween: qry = qry.Where(o => o.DueDate >= _criteria.DueDate && o.DueDate <= _criteria.DueDate2); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Due Date.", _criteria.DueDateOperator); break; } } #endregion #region TotalDue if (_criteria.TotalDueOperator != null) { switch (_criteria.TotalDueOperator) { case Operators.IsEqualTo: qry = qry.Where(o => o.TotalDue == _criteria.TotalDue); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.TotalDue != _criteria.TotalDue); break; case Operators.IsLessThan: qry = qry.Where(o => o.TotalDue < _criteria.TotalDue); break; case Operators.IsNotLessThan: qry = qry.Where(o => o.TotalDue >= _criteria.TotalDue); break; case Operators.IsGreaterThan: qry = qry.Where(o => o.TotalDue > _criteria.TotalDue); break; case Operators.IsNotGreaterThan: qry = qry.Where(o => o.TotalDue <= _criteria.TotalDue); break; case Operators.IsBetween: qry = qry.Where(o => o.TotalDue >= _criteria.TotalDue && o.TotalDue <= _criteria.TotalDue2); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Total Due.", _criteria.TotalDueOperator); break; } } #endregion #region CustomerStore if (_criteria.CustomerStoreOperator != null) { switch (_criteria.CustomerStoreOperator) { case Operators.IsNull: qry = qry.Where(o => o.CustomerStore == null); break; case Operators.IsNotNull: qry = qry.Where(o => o.CustomerStore != null); break; case Operators.IsEqualTo: qry = qry.Where(o => o.CustomerStore == _criteria.CustomerStore); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.CustomerStore != _criteria.CustomerStore); break; case Operators.Contains: qry = qry.Where(o => o.CustomerStore.Contains(_criteria.CustomerStore)); break; case Operators.DoesNotContain: qry = qry.Where(o => !o.CustomerStore.Contains(_criteria.CustomerStore)); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Customer Store.", _criteria.CustomerStoreOperator); break; } } #endregion #region CustomerName if (_criteria.CustomerNameOperator != null) { switch (_criteria.CustomerNameOperator) { case Operators.IsNull: qry = qry.Where(o => o.CustomerName == null); break; case Operators.IsNotNull: qry = qry.Where(o => o.CustomerName != null); break; case Operators.IsEqualTo: qry = qry.Where(o => o.CustomerName == _criteria.CustomerName); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.CustomerName != _criteria.CustomerName); break; case Operators.Contains: qry = qry.Where(o => o.CustomerName.Contains(_criteria.CustomerName)); break; case Operators.DoesNotContain: qry = qry.Where(o => !o.CustomerName.Contains(_criteria.CustomerName)); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Customer Name.", _criteria.CustomerNameOperator); break; } } #endregion #region TerritoryId if (_criteria.TerritoryIdOperator != null) { switch (_criteria.TerritoryIdOperator) { case Operators.IsNull: qry = qry.Where(o => o.TerritoryId == null); break; case Operators.IsNotNull: qry = qry.Where(o => o.TerritoryId != null); break; case Operators.IsEqualTo: qry = qry.Where(o => o.TerritoryId == _criteria.TerritoryId); break; case Operators.IsNotEqualTo: qry = qry.Where(o => o.TerritoryId != _criteria.TerritoryId); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Territory Id.", _criteria.TerritoryIdOperator); break; } } #endregion #region SalesPersonId if (_criteria.SalesPersonIdOperator != null) { switch (_criteria.SalesPersonIdOperator) { case Operators.IsNull: qry = qry.Where(o => o.SalesPersonId == null); break; case Operators.IsNotNull: qry = qry.Where(o => o.SalesPersonId != null); break; case Operators.IsOneOf: qry = qry.WhereIn(o => o.SalesPersonId, _criteria.SalesPersonId); break; case Operators.IsNoneOf: qry = qry.WhereNotIn(o => o.SalesPersonId, _criteria.SalesPersonId); break; default: ErrorList.Current.AddError("Unsupported operator {0} for the Sales Person Id.", _criteria.SalesPersonIdOperator); break; } } #endregion } // CUSTOM_CODE_START: add custom filter criteria to the result query for ReadList operation below // qry = qry.Where(o => o.FieldName == VALUE); // CUSTOM_CODE_END #endregion ErrorList.Current.AbortIfHasErrors(HttpStatusCode.BadRequest); res = qry.ToList(); } return(res); }