コード例 #1
0
        public string Delete(string reqType, string itemId)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                OrdersDbContext orderDbContext = new OrdersDbContext(connString);

                if (reqType != null && reqType == "DeleteFromPreference")
                {
                    string preferenceType   = this.ReadQueryStringData("preferenceType");
                    string preferenceIdType = null;
                    string preferenceName   = null;
                    if (preferenceType.ToLower() == "lab")
                    {
                        preferenceName   = "Labtestpreferences";
                        preferenceIdType = "//LabTestId";
                    }
                    else if (preferenceType.ToLower() == "imaging")
                    {
                        preferenceName   = "Imagingpreferences";
                        preferenceIdType = "//ImagingItemId";
                    }
                    else if (preferenceType.ToLower() == "medication")
                    {
                        preferenceName   = "Medicationpreferences";
                        preferenceIdType = "//MedicineId";
                    }

                    RbacUser            currentUser        = HttpContext.Session.Get <RbacUser>("currentuser");
                    EmployeePreferences employeePreference = (from pref in orderDbContext.EmployeePreferences
                                                              where pref.EmployeeId == currentUser.EmployeeId && pref.PreferenceName == preferenceName
                                                              select pref).FirstOrDefault();


                    XmlDocument prefXmlDocument = new XmlDocument();
                    prefXmlDocument.LoadXml(employeePreference.PreferenceValue);
                    // selecting the node of xml Document with tag LabTestId
                    XmlNodeList nodes = prefXmlDocument.SelectNodes(preferenceIdType);
                    //looping through the loop and checking the labtestId match or not
                    //if it is matched with LabtestId the delete the node
                    foreach (XmlNode node in nodes)
                    {
                        if (node.InnerXml == itemId.ToString())
                        {
                            node.ParentNode.RemoveChild(node);
                        }
                    }
                    //replacing the old value of employeePreference.PreferenceValue with new one
                    employeePreference.PreferenceValue = prefXmlDocument.InnerXml;
                    employeePreference.ModifiedBy      = currentUser.EmployeeId;
                    employeePreference.ModifiedOn      = DateTime.Now;
                    orderDbContext.SaveChanges();
                    responseData.Status  = "OK";
                    responseData.Results = itemId;
                }
            }

            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
コード例 #2
0
        public string Post()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                string          reqType        = this.ReadQueryStringData("reqType");
                OrdersDbContext orderDbContext = new OrdersDbContext(connString);

                if (reqType != null && reqType == "AddToPreference")
                {
                    string preferenceType   = this.ReadQueryStringData("preferenceType");
                    string preferenceName   = null;
                    string preferenceIdType = null;
                    if (preferenceType.ToLower() == "lab")
                    {
                        preferenceName   = "Labtestpreferences";
                        preferenceIdType = "LabTestId";
                    }
                    else if (preferenceType.ToLower() == "imaging")
                    {
                        preferenceName   = "Imagingpreferences";
                        preferenceIdType = "ImagingItemId";
                    }
                    else if (preferenceType.ToLower() == "medication")
                    {
                        preferenceName   = "Medicationpreferences";
                        preferenceIdType = "MedicineId";
                    }

                    string ItemId = this.ReadQueryStringData("itemId");
                    //string clientValue = this.ReadPostData();

                    RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser");

                    EmployeePreferences employeePreference = (from pref in orderDbContext.EmployeePreferences
                                                              where pref.EmployeeId == currentUser.EmployeeId && pref.PreferenceName == preferenceName
                                                              select pref).FirstOrDefault();

                    if (employeePreference == null)
                    {
                        //this is used to convert string into xml
                        XmlDocument xdoc = JsonConvert.DeserializeXmlNode("{\"Row\":{" + preferenceIdType + ":" + ItemId + "}}", "root");
                        //this is add new perference
                        EmployeePreferences employeePref = new EmployeePreferences();

                        employeePref.PreferenceName  = preferenceName;
                        employeePref.PreferenceValue = xdoc.InnerXml;
                        employeePref.EmployeeId      = currentUser.EmployeeId;
                        employeePref.CreatedBy       = currentUser.EmployeeId;;
                        employeePref.CreatedOn       = DateTime.Now;
                        employeePref.IsActive        = true;
                        orderDbContext.EmployeePreferences.Add(employeePref);
                        orderDbContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ItemId;
                    }
                    else
                    {
                        //creating object of XmlDocument
                        XmlDocument prefXmlDoc = new XmlDocument();
                        //loading the database PreferenceValue in object of XmlDocument(prefXmlDoc)
                        prefXmlDoc.LoadXml(employeePreference.PreferenceValue);
                        //creating xmlElement with tag Row
                        XmlElement Row = prefXmlDoc.CreateElement("Row");
                        //creating xmlElement with tag LabTestId/ImagingTypeId
                        XmlElement typeId = prefXmlDoc.CreateElement(preferenceIdType);
                        //provididng value to the element of LabTestId/ImagingTypeId
                        typeId.InnerText = ItemId;
                        //appending LabTestId/ImagingTypeId element ot Row element as child
                        Row.AppendChild(typeId);
                        //Appending the Row elemt to the root element of xml
                        prefXmlDoc.DocumentElement.AppendChild(Row);
                        //replacing the old value of employeePreference.PreferenceValue with new one
                        employeePreference.PreferenceValue = prefXmlDoc.InnerXml;
                        employeePreference.ModifiedBy      = currentUser.EmployeeId;
                        employeePreference.ModifiedOn      = DateTime.Now;


                        orderDbContext.Entry(employeePreference).State = EntityState.Modified;
                        orderDbContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ItemId;
                    }
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }