protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsPostBack) { if (Convert.ToInt32(ddlUsers.SelectedValue) > 0) { if (Convert.ToInt32(ddlWareHouse.SelectedValue) > 0) { string UserId = ddlUsers.SelectedValue; string WareHouseId = ddlWareHouse.SelectedValue; Classes.CUserWareHouseContainer cw = new Classes.CUserWareHouseContainer(); Models.MUserWareHouseContainer mw = new Models.MUserWareHouseContainer(); mw.UserId = UserId; mw.WareHouseId = WareHouseId; if (cw.Save(mw) > 0) { ShowSuccessMessage(); } else { ShowFailMessage(); } } else { ShowErrorModal("Please select a Ware House"); } } else { ShowErrorModal("Please select a User Id"); } } }
public int Save(Models.MUserWareHouseContainer model) { try { DB.UserWareHouseContainer uw = new DB.UserWareHouseContainer(); var query = from o in obj.UserWareHouseContainers where o.UserId == Convert.ToInt32(model.UserId) select o; if (query.Count() == 0) { uw.UserId = Convert.ToInt32(model.UserId); uw.WareHouseId = Convert.ToInt32(model.WareHouseId); obj.UserWareHouseContainers.InsertOnSubmit(uw); obj.SubmitChanges(); } else { foreach (var item in query) { item.WareHouseId = Convert.ToInt32(model.WareHouseId); } obj.SubmitChanges(); } return(1); } catch { return(-1); } }