private void addAgentType(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsAgentType> AgentTypes = JsonConvert.DeserializeObject <List <clsAgentType> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { string strName = AgentTypes[0].AgentType1.Trim().ToLower(); var obj = (from tbl in cntx.AgentTypes where tbl.IsDeleted == false && tbl.AgentType1.Trim().ToLower() == strName select tbl).FirstOrDefault(); if (obj == null) { var objAgentType = new ERP_CMS.DB_Code.AgentType() { AgentType1 = AgentTypes[0].AgentType1, IsDeleted = false, InsertedDate = DateTime.Now, InsertedBy = userID }; cntx.AgentTypes.Add(objAgentType); cntx.SaveChanges(); context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } else { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", "Agent Type Already Exists!"); context.Response.Write(objErr.ToString()); } } } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }
private void deleteAgentType(HttpContext context, int intID) { string output = ""; try { var JsonStr = context.Request["models"]; List <clsAgentType> AgentTypes = JsonConvert.DeserializeObject <List <clsAgentType> >(JsonStr); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { var objAgentTypes = new ERP_CMS.DB_Code.AgentType() { AgentTypeID = Convert.ToInt32(AgentTypes[0].AgentTypeID) }; //objAgentTypes.DeletedBy = userID; // Dim objBrands = New PortalModel.Brands With {.BrandID = intID} cntx.AgentTypes.Attach(objAgentTypes); objAgentTypes.IsDeleted = true; objAgentTypes.DeletedBy = userID; objAgentTypes.DeletedDate = DateTime.Now; // cntx.Brands.DeleteObject(objBrands) cntx.SaveChanges(); } context.Response.ContentType = "application/json; charset=utf-8"; context.Response.Write(JsonStr); } catch (Exception ex) { context.Response.ContentType = "application/json; charset=utf-8"; Newtonsoft.Json.Linq.JObject objErr = new Newtonsoft.Json.Linq.JObject(); objErr.Add("Errors", ex.Message); context.Response.Write(objErr.ToString()); } }