public override int?Save(string action) { var data = new ClientDataModel(); data.ClientId = SystemKeyId; data.Name = Name; data.Description = Description; data.SortOrder = SortOrder; if (action == "Insert") { var dtClient = ClientDataManager.DoesExist(data, SessionVariables.RequestProfile); if (dtClient.Rows.Count == 0) { ClientDataManager.Create(data, SessionVariables.RequestProfile); } else { throw new Exception("Record with given ID already exists."); } } else { ClientDataManager.Update(data, SessionVariables.RequestProfile); } // not correct ... when doing insert, we didn't get/change the value of ClientID ? return(data.ClientId); }
public HttpResponseMessage PostClient(ClientDataModel data) { int auditId = 10; data.ClientId = null; data.ClientId = ClientDataManager.Create(data, SessionVariables.RequestProfile); var response = Request.CreateResponse <ClientDataModel>(HttpStatusCode.Created, data); response.Headers.Location = new Uri(Request.RequestUri, "/api/clients/" + data.ClientId.ToString()); return(response); }
protected override void OnInit(EventArgs e) { try { var superKey = string.Empty; var newId = SystemEntityTypeDataManager.GetNextSequence("Client", (int)SystemEntity.Client, SessionVariables.RequestProfile); var clientData = new ClientDataModel(); var systemDevData = new SystemDevNumbersDataModel(); systemDevData.ApplicationUserId = SessionVariables.RequestProfile.AuditId; var dtnumbers = SystemDevNumbersDataManager.Search(systemDevData, SessionVariables.RequestProfile); var rangefrom = Convert.ToInt32(dtnumbers.Rows[0][SystemDevNumbersDataModel.DataColumns.RangeFrom].ToString()); var rangeto = Convert.ToInt32(dtnumbers.Rows[0][SystemDevNumbersDataModel.DataColumns.RangeTo].ToString()); if (Request.QueryString["SuperKey"] != null) { superKey = Request.QueryString["SuperKey"]; var data = new SuperKeyDetailDataModel(); data.SuperKeyId = Convert.ToInt32(superKey); data.SystemEntityTypeId = (int)SystemEntity.Client; var dt = SuperKeyDetailDataManager.Search(data, SessionVariables.RequestProfile); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { var key = (int)(dr[SuperKeyDetailDataModel.DataColumns.EntityKey]); clientData.ClientId = key; var clientdt = ClientDataManager.GetDetails(clientData, SessionVariables.RequestProfile); if (clientdt.Rows.Count == 1) { var row = clientdt.Rows[0]; if (Request.QueryString["Mode"].Equals("Test")) { clientData.ClientId = GetNextValidId(rangefrom); } clientData.Name = Convert.ToString(row[StandardDataModel.StandardDataColumns.Name]); clientData.Description = Convert.ToString(row[StandardDataModel.StandardDataColumns.Description]); clientData.SortOrder = (int)(row[StandardDataModel.StandardDataColumns.SortOrder]); ClientDataManager.Create(clientData, SessionVariables.RequestProfile); } } } } else if (Request.QueryString["SetId"] != null) { var key = int.Parse(Request.QueryString["SetId"]); clientData.ClientId = key; var clientdt = ClientDataManager.GetDetails(clientData, SessionVariables.RequestProfile); if (clientdt.Rows.Count == 1) { var row = clientdt.Rows[0]; var newclientdata = new ClientDataModel(); if (Request.QueryString["Mode"].Equals("Test")) { newclientdata.ClientId = newId = GetNextValidId(rangefrom); } newclientdata.Name = Convert.ToString(row[StandardDataModel.StandardDataColumns.Name]); newclientdata.Description = Convert.ToString(row[StandardDataModel.StandardDataColumns.Description]); newclientdata.SortOrder = (int)(row[StandardDataModel.StandardDataColumns.SortOrder]); UpdatedFKDepenedencies(key, newId); ClientDataManager.Delete(clientData, SessionVariables.RequestProfile); ClientDataManager.Create(newclientdata, SessionVariables.RequestProfile); } } else if (Request.QueryString["Mode"].Equals("Renumber")) { var seed = int.Parse(Request.QueryString["Seed"]); //ApplicationVariables.Seed; var increment = int.Parse(Request.QueryString["Increment"]); //ApplicationVariables.Increment; ClientDataManager.Renumber(seed, increment, SessionVariables.RequestProfile); } base.OnInit(e); Response.Redirect(Page.GetRouteUrl("ClientEntityRoute", new { Action = "Default", SetId = true }), false); } catch (Exception ex) { Response.Write(ex.Message); } }