private void CreateNewStore() { using (TransactionScope scope = new TransactionScope()) { Store st = new Store(); st.NAME = txtName.Text.Trim(); st.ADDRESS = txtAddress.Text.Trim(); st.CITY_ID = Convert.ToInt32(ddlCity.SelectedValue); st.PHONE = txtPhone.Text.Trim(); st.FAX = string.Empty; st.START_CAPITAL = Convert.ToDecimal(txtStartCapital.Text); //st.CURRENT_CAPITAL = Convert.ToDecimal(txtCurrentCapital.Text); //st.APPLY_DATE = Convert.ToDateTime(txtApplyDate.Text); //st.REVENUE_BEFORE_APPLY = Convert.ToDecimal(txtTotalRevenueBefore.Text); //st.TOTAL_COST_BEFORE = Convert.ToDecimal(txtTotalCostBefore.Text); //st.TOTAL_INVESMENT_BEFORE = Convert.ToDecimal(txtTotalInvesmentBefore.Text); st.REGISTER_DATE = Convert.ToDateTime(txtRegisterDate.Text); st.ACTIVE = rdbActive.Checked; st.NOTE = txtNote.Text.Trim(); st.SEARCH_TEXT = string.Format("{0} {1} {2}", st.NAME, st.ADDRESS, st.PHONE); using (var rb = new RentBikeEntities()) { rb.Stores.Add(st); rb.SaveChanges(); } using (var rb1 = new RentBikeEntities()) { var item = rb1.InOutTypes.FirstOrDefault(s =>s.NAME == "Nhập vốn"); InOut io = new InOut(); io.IN_AMOUNT = Convert.ToDecimal(txtStartCapital.Text.Replace(",", string.Empty)); io.OUT_AMOUNT = 0; io.CONTRACT_ID = -1; io.PERIOD_ID = -1; io.RENT_TYPE_ID = -1; io.PERIOD_DATE = DateTime.Now; io.MORE_INFO = "Vốn đầu tư ban đầu khi đăng ký cửa hàng"; io.STORE_ID = st.ID; io.INOUT_TYPE_ID = item.ID; io.INOUT_DATE = DateTime.Now; io.SEARCH_TEXT = string.Format("{0} {1} ngày {2}", io.MORE_INFO, io.IN_AMOUNT, io.INOUT_DATE); rb1.InOuts.Add(io); rb1.SaveChanges(); StoreFee sf = new StoreFee(); sf.STORE_ID = st.ID; sf.FEE_PERCENT = 0; rb1.StoreFees.Add(sf); rb1.SaveChanges(); } WriteLog(Constants.ACTION_CREATE_STORE, false); scope.Complete(); } }