public tbl_AccessoryAttributesHeader UpdateAccessoriesAttributes( tbl_AccessoryAttributesHeader header , List <tbl_AccessoryAttributesDetails> detailsToAdd , List <tbl_AccessoryAttributesDetails> detailsToUpdate, int userIserial) { try { //InsertAllNewAccessoryToAx(detailsToAdd, header, true); using (var context = new WorkFlowManagerDBEntities()) { // var htemp = context.tbl_AccessoryAttributesHeader.FirstOrDefault(x => x.Code == header.Code); // GenericUpdate(htemp, header, context); // var colorGroup = context.TblLkpColorGroups.FirstOrDefault(x => x.Code == "Acc").Iserial; foreach (var item in detailsToUpdate) { var dtemp = context.tbl_AccessoryAttributesDetails.FirstOrDefault( x => x.Iserial == item.Iserial); GenericUpdate(dtemp, item, context); } if (SharedOperation.UseAx()) { try { UpdateAccDetailsInAX(detailsToUpdate, userIserial); InsertAllNewAccessoryToAx(detailsToUpdate, header, false, userIserial); } catch (Exception) { } } foreach (var item in detailsToAdd) { context.tbl_AccessoryAttributesDetails.AddObject(item); } if (SharedOperation.UseAx()) { try { UpdateAccDetailsInAX(detailsToAdd, userIserial); } catch (Exception) { } } context.SaveChanges(); return(context.tbl_AccessoryAttributesHeader.Include(nameof(tbl_AccessoryAttributesHeader.tbl_AccessoryAttributesDetails)).FirstOrDefault(x => x.Code == header.Code)); } } catch (Exception ex) { throw ex; } }
public tbl_AccessoryAttributesHeader AddAllNewAccessoriesAttributes(tbl_AccessoryAttributesHeader header , List <tbl_AccessoryAttributesDetails> details, bool isSizeInHeader, int userIserial) { try { using (var context = new WorkFlowManagerDBEntities()) { if (!context.tbl_AccessoryAttributesHeader.Any(x => x.Code == header.Code)) { context.tbl_AccessoryAttributesHeader.AddObject(header); } // var colorGroup = context.TblLkpColorGroups.FirstOrDefault(x => x.Code == "Acc").Iserial; if (SharedOperation.UseAx()) { try { InsertAllNewAccessoryToAx(details, header, isSizeInHeader, userIserial); } catch (Exception) { } } foreach (var item in details) { context.tbl_AccessoryAttributesDetails.AddObject(item); } context.SaveChanges(); return(context.tbl_AccessoryAttributesHeader.Include(nameof(tbl_AccessoryAttributesHeader.tbl_AccessoryAttributesDetails)).FirstOrDefault(x => x.Code == header.Code)); } } catch (Exception ex) { throw ex; } }
private void InsertAllNewAccessoryToAx(IEnumerable <tbl_AccessoryAttributesDetails> listObjToPost , tbl_AccessoryAttributesHeader objToPost, bool isSizeInCode, int userIserial) { try { using (var context = new WorkFlowManagerDBEntities()) { var axapta = new Axapta();//Ready To be Dependent from Ax; var credential = new NetworkCredential("bcproxy", "around1"); TblAuthUser userToLogin; using (var model = new WorkFlowManagerDBEntities()) { userToLogin = model.TblAuthUsers.SingleOrDefault(x => x.Iserial == userIserial); } axapta.LogonAs(userToLogin.User_Win_Login, userToLogin.User_Domain, credential, "Ccm", null, null, null); var itemId = objToPost.Code.Trim(); var tableName = "InventTable"; var axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); var tblLkpItemGroupType = context.tbl_lkp_ItemGroupType.FirstOrDefault(x => x.Iserial == context.tbl_lkp_AccessoryGroup .FirstOrDefault( g => g.Iserial == objToPost.AccGroup) .tbl_lkp_ItemGroupType); if (tblLkpItemGroupType != null) { var itmGroup = tblLkpItemGroupType.Code; axaptaRecord.set_Field("ItemGroupId", itmGroup); } else { axaptaRecord.set_Field("ItemGroupId", "ACCESSORIES"); } axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ItemName", objToPost.Descreption ?? itemId); axaptaRecord.set_Field("ModelGroupID", "STD"); axaptaRecord.set_Field("ItemType", 0); axaptaRecord.set_Field("DimGroupId", "ACC"); //Commit the record to the database. axaptaRecord.Insert(); tableName = "InventTableModule"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 0); if (objToPost.UoMID != null) { axaptaRecord.set_Field ("UnitId", context.tbl_lkp_UoM .Where(x => x.Iserial == objToPost.UoMID) .Select(x => x.Ename) .SingleOrDefault() ); } // axaptaRecord.Insert(); axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 1); // axaptaRecord.Insert(); axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("ModuleType", 2); // axaptaRecord.Insert(); tableName = "InventItemLocation"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("InventDIMID", "AllBlank"); // Commit the record to the database. axaptaRecord.Insert(); foreach (var item in listObjToPost) { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateConfig", listObjToPost.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } // if (!isSizeInCode) // { try { var importNew = axapta.CreateAxaptaObject("CreateProductionJournals"); importNew.Call("CreateSize", listObjToPost.Select(x => x.Code).FirstOrDefault(), item); } catch (Exception) { } //--------------------------------------------// //--------------------------------------------// //--------------------------------------------// try { tableName = "InventDimCombination"; axaptaRecord = axapta.CreateAxaptaRecord(tableName); axaptaRecord.Clear(); axaptaRecord.InitValue(); axaptaRecord.set_Field("ItemId", itemId); axaptaRecord.set_Field("InventSizeID", item.Size); axaptaRecord.set_Field("ConfigId", item.Configuration); //Commit the record to the database. axaptaRecord.Insert(); } catch (Exception) { } //--------------------------------------------// //--------------------------------------------// //--------------------------------------------// // } } axapta.Logoff(); } } catch (Exception ex) { throw ex; } }