public void deleteExtraMOA(int moa_bonus_id) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { //finding old exScope of exMOU. List <MOAPartnerScope> exList = db.MOAPartnerScopes.Where(x => x.moa_bonus_id == moa_bonus_id).ToList(); exList.Clear(); db.Entry(exList).State = EntityState.Modified; //add new record of MOuPartnerScope MOABonu m = db.MOABonus.Find(moa_bonus_id); db.MOABonus.Remove(m); db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } return; }
public void addExtraMOA(ExMOAAdd input, int moa_id) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { DateTime sign_date = DateTime.ParseExact(input.ExMOABasicInfo.ex_moa_sign_date, "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime end_date = DateTime.ParseExact(input.ExMOABasicInfo.ex_moa_end_date, "dd/MM/yyyy", CultureInfo.InvariantCulture); //add MOABonus MOABonu objMOABonusAdded = db.MOABonus.Add(new MOABonu { moa_bonus_code = input.ExMOABasicInfo.ex_moa_code, moa_bonus_decision_date = sign_date, moa_bonus_end_date = end_date, moa_id = moa_id, evidence = "" }); db.SaveChanges(); //check PartnerScope and add MOAPartnerScope. foreach (PartnerScopeInfoMOA psMOA in input.PartnerScopeInfoMOA.ToList()) { foreach (int scopeItem in psMOA.scopes_id.ToList()) { int partner_scope_id_item = 0; PartnerScope psCheck = db.PartnerScopes.Where(x => x.partner_id == psMOA.partner_id && x.scope_id == scopeItem).First(); if (psCheck == null) { PartnerScope psAdded = db.PartnerScopes.Add(new PartnerScope { partner_id = psMOA.partner_id, scope_id = scopeItem, reference_count = 1 }); partner_scope_id_item = psAdded.partner_scope_id; } else { partner_scope_id_item = psCheck.partner_scope_id; psCheck.reference_count += 1; } db.SaveChanges(); //add to MOAPartnerScope db.MOAPartnerScopes.Add(new MOAPartnerScope { partner_scope_id = partner_scope_id_item, moa_id = moa_id, moa_bonus_id = objMOABonusAdded.moa_bonus_id }); db.SaveChanges(); } } db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }