public int Sava(Model.UseCarModel.usecarapplyform myForm) { UseCarApplyForm u; bool found = false; if (myForm.UseCarApplyFormID == -1) { // new record u = new UseCarApplyForm(); db.UseCarApplyForm.InsertOnSubmit(u); found = true; } else { // existing record u = (from myUseCarApplyForm in db.UseCarApplyForm where myUseCarApplyForm.UseCarApplyFormID == myForm.UseCarApplyFormID select myUseCarApplyForm).FirstOrDefault(); if (u != null) { found = true; int id = (int)myForm.UseCarApplyFormID; u.UseCarApplyFormID = id; } } if (found) { u.ApplyReason = myForm.ApplyReason; u.ApplyUserName = myForm.ApplyUserName; u.BeginTime = myForm.BeginTime; u.EndTime = myForm.EndTime; u.Comment = myForm.Comment; u.StartDestination = myForm.StartDestination; u.EndDestination = myForm.EndDestination; u.UseCarTypeID = myForm.usecartype.UseCarTypeID; u.ApplyStatus = myForm.ApplyStatus; u.WFID = myForm.WFID; try { db.SubmitChanges(); foreach (usecaranduser usecaranduser in myForm.Usecaranduser) { usecaranduser user = new Model.UseCarModel.usecaranduser(); user.UseCarUserId = usecaranduser.UseCarUserId; user.UseCarApplyFormID = u.UseCarApplyFormID; user.Name = usecaranduser.Name; user.Email = usecaranduser.Email; new YunShanOA.DataAccess.UseCar.UsecarAndUserHelp().Save(user); } db.SubmitChanges(); } catch (ChangeConflictException) { db.ChangeConflicts.ResolveAll(RefreshMode.OverwriteCurrentValues); db.SubmitChanges(); } return u.UseCarApplyFormID; } else return -1; }
public int Sava(Model.UseCarModel.usecarapplyform myForm) { UseCarApplyForm u; bool found = false; if (myForm.UseCarApplyFormID == -1) { // new record u = new UseCarApplyForm(); db.UseCarApplyForm.InsertOnSubmit(u); found = true; } else { // existing record u = (from myUseCarApplyForm in db.UseCarApplyForm where myUseCarApplyForm.UseCarApplyFormID == myForm.UseCarApplyFormID select myUseCarApplyForm).FirstOrDefault(); if (u != null) { found = true; int id = (int)myForm.UseCarApplyFormID; u.UseCarApplyFormID = id; } } if (found) { u.ApplyReason = myForm.ApplyReason; u.ApplyUserName = myForm.ApplyUserName; u.BeginTime = myForm.BeginTime; u.EndTime = myForm.EndTime; u.Comment = myForm.Comment; u.StartDestination = myForm.StartDestination; u.EndDestination = myForm.EndDestination; u.UseCarTypeID = myForm.usecartype.UseCarTypeID; u.ApplyStatus = myForm.ApplyStatus; u.WFID = myForm.WFID; try { db.SubmitChanges(); foreach (usecaranduser usecaranduser in myForm.Usecaranduser) { usecaranduser user = new Model.UseCarModel.usecaranduser(); user.UseCarUserId = usecaranduser.UseCarUserId; user.UseCarApplyFormID = u.UseCarApplyFormID; user.Name = usecaranduser.Name; user.Email = usecaranduser.Email; new YunShanOA.DataAccess.UseCar.UsecarAndUserHelp().Save(user); } db.SubmitChanges(); } catch (ChangeConflictException) { db.ChangeConflicts.ResolveAll(RefreshMode.OverwriteCurrentValues); db.SubmitChanges(); } return(u.UseCarApplyFormID); } else { return(-1); } }