public IHttpActionResult ManageAnimalSupplier() { try { string OrganizationOid = HttpContext.Current.Request.Form["OrganizationOid"].ToString(); string FinanceYearOid = HttpContext.Current.Request.Form["FinanceYearOid"].ToString(); XpoTypesInfoHelper.GetXpoTypeInfoSource(); XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier)); List <ManageAnimalSupplier_Model> list_detail = new List <ManageAnimalSupplier_Model>(); XPObjectSpaceProvider directProvider = new XPObjectSpaceProvider(scc, null); IObjectSpace ObjectSpace = directProvider.CreateObjectSpace(); IList <ManageAnimalSupplier> collection = ObjectSpace.GetObjects <ManageAnimalSupplier>(CriteriaOperator.Parse(" GCRecord is null and Status = 1 and OrganizationOid=? and FinanceYearOid = ?", OrganizationOid, FinanceYearOid)); //ManageAnimalSupplier ObjMaster; //ObjMaster = ObjectSpace.FindObject<ManageAnimalSupplier>(CriteriaOperator.Parse("GCRecord is null and StockType = 1 and OrganizationOid =? and FinanceYearOid = ? ", OrganizationOid, FinanceYearOid)); foreach (ManageAnimalSupplier row in collection) { ManageAnimalSupplier_Model Model = new ManageAnimalSupplier_Model(); Model.Oid = row.Oid.ToString(); Model.FinanceYearOid = row.FinanceYearOid.Oid.ToString(); Model.FinanceYear = row.FinanceYearOid.YearName; Model.OrgZoneOid = row.OrgZoneOid.Oid.ToString(); Model.OrgZone = row.OrgZoneOid.OrganizeNameTH; Model.OrganizationOid = row.OrganizationOid.Oid.ToString(); Model.Organization = row.OrganizationOid.SubOrganizeName; Model.AnimalSupplieOid = row.AnimalSupplieOid.Oid.ToString(); Model.AnimalSupplie = row.AnimalSupplieOid.AnimalSupplieName; Model.ZoneQTY = row.ZoneQTY; Model.CenterQTY = row.CenterQTY; Model.OfficeQTY = row.OfficeQTY; Model.OfficeGAPQTY = row.OfficeGAPQTY; Model.OfficeBeanQTY = row.OfficeBeanQTY; Model.Status = row.Status.ToString(); Model.SortID = row.SortID; list_detail.Add(Model); } return(Ok(true)); } catch (Exception ex) { //Error case เกิดข้อผิดพลาด UserError err = new UserError(); err.code = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ err.message = ex.Message; // Return resual return(BadRequest(ex.Message)); } }
public HttpResponseMessage ManageAnimalSupplier() { string OrganizationOid; string FinanceYearOid; try { OrganizationOid = HttpContext.Current.Request.Form["OrganizationOid"].ToString(); FinanceYearOid = HttpContext.Current.Request.Form["FinanceYearOid"].ToString(); XpoTypesInfoHelper.GetXpoTypeInfoSource(); XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier)); List<ManageAnimalSupplier_Model> list_detail = new List<ManageAnimalSupplier_Model>(); XPObjectSpaceProvider directProvider = new XPObjectSpaceProvider(scc, null); IObjectSpace ObjectSpace = directProvider.CreateObjectSpace(); IList<ManageAnimalSupplier> collection = ObjectSpace.GetObjects<ManageAnimalSupplier>(CriteriaOperator.Parse(" GCRecord is null and Status = 1 and OrgZoneOid=? and FinanceYearOid=? ", OrganizationOid, FinanceYearOid)); double Weight = 0; if (collection.Count > 0) { foreach (ManageAnimalSupplier row in collection) { ManageAnimalSupplier_Model ManageAnimal = new ManageAnimalSupplier_Model(); ManageAnimal.Oid = row.Oid.ToString(); ManageAnimal.OrgZoneOid = row.OrgZoneOid.Oid.ToString(); ManageAnimal.OrgZone = row.OrgZoneOid.OrganizeNameTH; ManageAnimal.OrganizationOid = row.OrganizationOid.Oid.ToString(); ManageAnimal.Organization = row.OrganizationOid.SubOrganizeName; ManageAnimal.FinanceYearOid = row.FinanceYearOid.Oid.ToString(); ManageAnimal.FinanceYear = row.FinanceYearOid.YearName; ManageAnimal.AnimalSupplieOid = row.AnimalSupplieOid.Oid.ToString(); ManageAnimal.AnimalSupplie = row.AnimalSupplieOid.AnimalSupplieName; ManageAnimal.ZoneQTY = row.ZoneQTY; ManageAnimal.CenterQTY = row.CenterQTY; ManageAnimal.OfficeQTY = row.OfficeQTY; ManageAnimal.OfficeGAPQTY = row.OfficeGAPQTY; ManageAnimal.OfficeBeanQTY = row.OfficeBeanQTY; List<ManageSubAnimalSupplier_Model> detail = new List<ManageSubAnimalSupplier_Model>(); foreach (ManageSubAnimalSupplier row2 in row.ManageSubAnimalSuppliers) { ManageSubAnimalSupplier_Model item = new ManageSubAnimalSupplier_Model(); item.ProvinceQTY = row2.ProvinceQTY; item.Province = row2.ProvinceOid.ProvinceNameTH; detail.Add(item); } ManageAnimal.Detail = detail; ManageAnimal.SumProvinceQTY = row.SumProvinceQTY.Value; list_detail.Add(ManageAnimal); } return Request.CreateResponse(HttpStatusCode.OK, list_detail); } else { UserError err = new UserError(); err.code = "5"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ err.message = "No data"; // Return resual return Request.CreateResponse(HttpStatusCode.BadRequest, err); } } catch (Exception ex) { //Error case เกิดข้อผิดพลาด UserError err = new UserError(); err.code = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ err.message = ex.Message; // Return resual return Request.CreateResponse(HttpStatusCode.BadRequest, ex); } }