#region ButtonSave
protected void btnsave_Click(object sender, EventArgs e)
{
if (Code != String.Empty && !string.IsNullOrEmpty(Code))
{
if (UpdateAccounts())
{
mvMarketFactors.ActiveViewIndex = 0;
msgWarning.Visible = true;
lblmessage.Text = "Successfully Updated";
BindGrid();
}
}
else
{
if (SaveAccounts())
{
mvMarketFactors.ActiveViewIndex = 0;
msgWarning.Visible = true;
lblmessage.Text = "Successfully Inserted";
BindGrid();
}
}
}
#endregion
#region SaveAccounts
private bool SaveAccounts()
{
bool flag = true;
var osoID = Convert.ToInt32(ddlOso.SelectedValue);
var ManagersID = Convert.ToInt32(ddlManagers.SelectedValue);
TcaManager TcaManagersID = db.TcaManagers.Where(x => x.TcaManagerID == ManagersID).FirstOrDefault();
MstrOSoOfficesMarket OsoID = db.MstrOSoOfficesMarkets.Where(x => x.OSOOfficesMarketsPkID == osoID).FirstOrDefault();
MarketFactor tbl = new MarketFactor();
tbl.Title = txtTitle.Text.Trim();
tbl.Summary = txtSummary.Text.Trim();
tbl.Details = txtDetails.Text.Trim();
if (RBIsPositiveYes.Checked == true)
{
tbl.IsPositive = 1;
}
else
{
tbl.IsPositive = 0;
}
if (RByes.Checked == true)
{
tbl.IsActive = 1;
}
else
{
tbl.IsActive = 0;
}
tbl.MstrOSoOfficesMarket = OsoID;
tbl.TcaManager = TcaManagersID;
tbl.CreatedBy = Session["LoginUser"].ToString();
tbl.IsDeleted = 0;
tbl.CreatedDate = DateTime.UtcNow;
db.AddToMarketFactors(tbl);
db.SaveChanges();
var attachmentMarketFactorsID = 0;
attachmentMarketFactorsID = tbl.MarketFactorsPkID;
var filepkID = 0;
AddAttachments(filepkID, attachmentMarketFactorsID);
return flag;
}
#endregion
#region UpdateAccounts
private bool UpdateAccounts()
{
bool flag = true;
var MarketFactorsPkID = Convert.ToInt32(Code);
var osoID = Convert.ToInt32(ddlOso.SelectedValue);
var ManagersID = Convert.ToInt32(ddlManagers.SelectedValue);
MarketFactor tbl = db.MarketFactors.First(i => i.MarketFactorsPkID == MarketFactorsPkID);
tbl.Title = txtTitle.Text.Trim();
tbl.Summary = txtSummary.Text.Trim();
tbl.Details = txtDetails.Text.Trim();
if (RByes.Checked == true)
{
tbl.IsActive = 1;
}
else
{
tbl.IsActive = 0;
}
TcaManager TcaManagersID = db.TcaManagers.Where(x => x.TcaManagerID == ManagersID).FirstOrDefault();
MstrOSoOfficesMarket OsoID = db.MstrOSoOfficesMarkets.Where(x => x.OSOOfficesMarketsPkID == osoID).FirstOrDefault();
tbl.MstrOSoOfficesMarket = OsoID;
tbl.TcaManager = TcaManagersID;
tbl.ModifiedBy = Session["LoginUser"].ToString();
tbl.ModifiedDate = DateTime.UtcNow;
//Save the changes back to database.
db.SaveChanges();
return flag;
}
#endregion
protected void btnsave_Click(object sender, EventArgs e)
{
if (Code != String.Empty && !string.IsNullOrEmpty(Code))
{
if (UpdateAccounts())
{
mvMarketFactors.ActiveViewIndex = 0;
msgWarning.Visible = true;
lblmessage.Text = "Successfully Updated";
BindGrid();
}
}
else
{
if (SaveAccounts())
{
mvMarketFactors.ActiveViewIndex = 0;
msgWarning.Visible = true;
lblmessage.Text = "Successfully Inserted";
BindGrid();
}
}
}
#endregion
#region SaveAccounts
private bool SaveAccounts()
{
bool flag = true;
var osoID = Convert.ToInt32(ddlOso.SelectedValue);
var ManagersID = Convert.ToInt32(ddlManagers.SelectedValue);
TcaManager TcaManagersID = db.TcaManagers.Where(x => x.TcaManagerID == ManagersID).FirstOrDefault();
MstrOSoOfficesMarket OsoID = db.MstrOSoOfficesMarkets.Where(x => x.OSOOfficesMarketsPkID == osoID).FirstOrDefault();
MarketFactor tbl = new MarketFactor();
tbl.Title = txtTitle.Text.Trim();
tbl.Summary = txtSummary.Text.Trim();
tbl.Details = txtDetails.Text.Trim();
if (RBIsPositiveYes.Checked == true)
{
tbl.IsPositive = 1;
}
else
{
tbl.IsPositive = 0;
}
if (RByes.Checked == true)
{
tbl.IsActive = 1;
}
else
{
tbl.IsActive = 0;
}
tbl.MstrOSoOfficesMarket = OsoID;
tbl.TcaManager = TcaManagersID;
tbl.CreatedBy = Session["LoginUser"].ToString();
tbl.IsDeleted = 0;
tbl.CreatedDate = DateTime.UtcNow;
db.AddToMarketFactors(tbl);
db.SaveChanges();
var attachmentMarketFactorsID = 0;
attachmentMarketFactorsID = tbl.MarketFactorsPkID;
var filepkID = 0;
AddAttachments(filepkID, attachmentMarketFactorsID);
return flag;
}
#endregion
#region UpdateAccounts
private bool UpdateAccounts()
{
bool flag = true;
var MarketFactorsPkID = Convert.ToInt32(Code);
var osoID = Convert.ToInt32(ddlOso.SelectedValue);
var ManagersID = Convert.ToInt32(ddlManagers.SelectedValue);
MarketFactor tbl = db.MarketFactors.First(i => i.MarketFactorsPkID == MarketFactorsPkID);
tbl.Title = txtTitle.Text.Trim();
tbl.Summary = txtSummary.Text.Trim();
tbl.Details = txtDetails.Text.Trim();
if (RByes.Checked == true)
{
tbl.IsActive = 1;
}
else
{
tbl.IsActive = 0;
}
TcaManager TcaManagersID = db.TcaManagers.Where(x => x.TcaManagerID == ManagersID).FirstOrDefault();
MstrOSoOfficesMarket OsoID = db.MstrOSoOfficesMarkets.Where(x => x.OSOOfficesMarketsPkID == osoID).FirstOrDefault();
tbl.MstrOSoOfficesMarket = OsoID;
tbl.TcaManager = TcaManagersID;
tbl.ModifiedBy = Session["LoginUser"].ToString();
tbl.ModifiedDate = DateTime.UtcNow;
//Save the changes back to database.
db.SaveChanges();
return flag;
}
#endregion