示例#1
0
        }//END OF DELETE DETAILS

        public int SetDetails(CustomerDataObject customerobj)
        {//SET DETAILS BEGINS
            CMSLogger.SetProperties("AuthToken", customerobj.Adminid.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.ToString());
            CMSLogger.log.Info("setDetailsInvoked");

            int result = 0;

            try
            {
                MySqlCommand cmd;
                cnn.Open();
                cmd             = new MySqlCommand("setDetails", cnn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", customerobj.CustomerName);
                cmd.Parameters.AddWithValue("@age", customerobj.Age);
                cmd.Parameters.AddWithValue("@gender", customerobj.Gender);
                cmd.Parameters.AddWithValue("@phone", customerobj.Phone);
                cmd.Parameters.AddWithValue("@address", customerobj.Address);
                cmd.Parameters.AddWithValue("@city", customerobj.City);
                cmd.Parameters.AddWithValue("@emailid", customerobj.Emailid);
                cmd.Parameters.AddWithValue("@adminid", customerobj.Adminid);
                result = cmd.ExecuteNonQuery();
                Console.WriteLine("num of rows affected" + result);
                cnn.Close();
            }
            catch (Exception ex)
            {
                CMSLogger.SetProperties("AuthToken", customerobj.Adminid.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.ToString());
                CMSLogger.log.Error(ex.Message, ex);

                cnn.Close();
                throw;
            }
            return(result);
        }//SET DETAILS ENDS
 public int IdAssigner(List <CustomerDataObject> CustomerList, CustomerDataObject Record)
 {
     if (CustomerList.Count == 0)
     {
         return(2500);
     }
     else
     {
         return(CustomerList.Last <CustomerDataObject>().Id + 1);
     }
 }
 public bool IsNull(CustomerDataObject Record)
 {
     if (Record.Emailid == null || Record.Gender == null || Record.CustomerName == null || Record.Phone == 0 || Record.Address == null || Record.City == null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public int UpdateDetails(CustomerDataObject Record)
 {
     try
     {
         JsonCustomerDataBaseManager JsonDBM      = new JsonCustomerDataBaseManager();
         List <CustomerDataObject>   CustomerList = JsonDBM.ReadFile("DB.json");
         CustomerList = JsonDBM.UpdateList(CustomerList, Record);
         return(1);
     }
     catch
     {
         throw;
     }
 }
 public int DeleteDetails(Retrieve_message Criteria)
 {
     try {
         JsonCustomerDataBaseManager JsonDBM      = new JsonCustomerDataBaseManager();
         List <CustomerDataObject>   CustomerList = JsonDBM.ReadFile("DB.json");
         CustomerDataObject          Record       = new CustomerDataObject();
         Record.Id      = Criteria.id;
         Record.Adminid = Criteria.Adminid;
         CustomerList   = JsonDBM.DeleteFromList(CustomerList, Record);
         return(1);
     }
     catch
     {
         throw;
     }
 }
        public List <CustomerDataObject> UpdateList(List <CustomerDataObject> CustomerList, CustomerDataObject Record)
        {
            try
            {
                int RecordIndex = CustomerList.FindIndex(delegate(CustomerDataObject Obj) { return(Obj.Id == Record.Id && Obj.Adminid == Record.Adminid); });
                if (RecordIndex < 0 || RecordIndex >= CustomerList.Count)
                {
                    throw new Exception("Unauthorized. No Such CustomerDataObject.");
                }
                CustomerDataObject[] TempArray = new CustomerDataObject[CustomerList.Count];

                CustomerDataObject        CurrentRecord = CustomerList.Find(delegate(CustomerDataObject Obj) { return(Obj.Id == Record.Id && Obj.Adminid == Record.Adminid); });
                List <CustomerDataObject> Testlist      = CustomerList.SkipWhile(cc => cc.Emailid == CurrentRecord.Emailid).ToList <CustomerDataObject>();
                if (CustomerList.Exists(delegate(CustomerDataObject Obj) { return(Obj.Emailid == Record.Emailid); }))
                {
                    if (CustomerList.Find(delegate(CustomerDataObject Obj) { return(Obj.Emailid == Record.Emailid); }).Id != Record.Id)
                    {
                        throw new Exception("Duplicate Email");
                    }
                }
                if (CustomerList.Exists(delegate(CustomerDataObject Obj) { return(Obj.Phone == Record.Phone); }))
                {
                    if (CustomerList.Find(delegate(CustomerDataObject Obj) { return(Obj.Phone == Record.Phone); }).Id != Record.Id)
                    {
                        throw new Exception("Duplicate Phone");
                    }
                }

                CustomerList[RecordIndex] = Record;
                return(CustomerList);
            }
            catch
            {
                throw;
            }
        }
示例#7
0
        public List <CustomerDataObject> GetDetailsAll(Retrieve_message message) //string searchparam,string searchvalue,int adminid,int start_index,int end_index,string sortparam)
        {                                                                        //get detailsAll begin
            CMSLogger.SetProperties("AuthToken", message.Adminid.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.ToString());
            CMSLogger.log.Info("GetDetailsALlInvoked");

            CustomerDataObject[]      obj = new CustomerDataObject[100];// = new DataBase[50]; //warning 100 manually coded here
            MySqlCommand              cmd;
            DataTable                 dataTable = new DataTable();
            List <CustomerDataObject> customer  = new List <CustomerDataObject>();

            try
            {
                if (message.Adminid == 9999)
                {
                    cmd = new MySqlCommand("dummygetDetailsAll", cnn);
                }
                else
                {
                    cmd = new MySqlCommand("getDetailsAll", cnn);
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@c_searchparam", message.Searchparam);
                cmd.Parameters.AddWithValue("@c_searchvalue", message.Searchvalue);
                cmd.Parameters.AddWithValue("@c_adminid", message.Adminid);
                cmd.Parameters.AddWithValue("@c_start_index", message.Start_index);
                cmd.Parameters.AddWithValue("@c_end_index", message.End_index);
                cmd.Parameters.AddWithValue("@c_sortparam", message.Sortparam);

                //cmd.Parameters.AddWithValue("@c_searchparam", "gender");
                //cmd.Parameters.AddWithValue("@c_searchvalue", "male");
                //cmd.Parameters.AddWithValue("@c_adminid", 9999);
                //cmd.Parameters.AddWithValue("@c_start_index", 1);
                //cmd.Parameters.AddWithValue("@c_end_index", 7);
                //cmd.Parameters.AddWithValue("@c_sortparam", "age");

                //cnn.Close();

                cnn.Open();
                using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                {
                    da.Fill(dataTable);
                    cnn.Close();
                }

                //to print the datatable
                //to build db object


                int dbobj_count = 0;
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    int count = 0;

                    obj[dbobj_count] = new CustomerDataObject();
                    foreach (var item in dataRow.ItemArray)
                    {
                        Console.WriteLine(item);
                        count++;

                        switch (count)
                        {
                        case 1: obj[dbobj_count].Id = (int)item; Console.WriteLine(obj[dbobj_count].Id); break;

                        case 2: obj[dbobj_count].CustomerName = (string)item; Console.WriteLine(obj[dbobj_count].CustomerName); break;

                        case 3: obj[dbobj_count].Gender = (string)item; break;

                        case 4: obj[dbobj_count].Age = (int)item; break;

                        case 5: obj[dbobj_count].Phone = (long)item; break;

                        case 6: obj[dbobj_count].Address = (string)item; break;

                        case 7: obj[dbobj_count].City = (string)item; break;

                        case 8: obj[dbobj_count].Emailid = (string)item; break;

                        case 9: obj[dbobj_count].Adminid = (int)item; break;
                        }
                    }

                    customer.Add(obj[dbobj_count]);
                    dbobj_count++;
                }
            }
            catch (Exception ex)
            {
                cnn.Close();
                CMSLogger.SetProperties("AuthToken", message.Adminid.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.ToString());
                CMSLogger.log.Error(ex.Message, ex);
                throw ex;
            }

            return(customer);
        } //get detailsAll end
 public List <CustomerDataObject> InsertIntoList(List <CustomerDataObject> CustomerList, CustomerDataObject Record)
 {
     try
     {
         Record.Id = IdAssigner(CustomerList, Record);
         if (IsNull(Record))
         {
             throw new Exception("Required Field Can't be Null");
         }
         if (CustomerList.Exists(delegate(CustomerDataObject Obj) { return(Obj.Emailid == Record.Emailid); }))
         {
             throw new Exception("Duplicate Email");
         }
         if (CustomerList.Exists(delegate(CustomerDataObject Obj) { return(Obj.Phone == Record.Phone); }))
         {
             throw new Exception("Duplicate Phone");
         }
         CustomerList.Add(Record);
         return(CustomerList);
     }
     catch
     {
         throw;
     }
 }
 public List <CustomerDataObject> DeleteFromList(List <CustomerDataObject> CustomerList, CustomerDataObject Record)
 {
     try
     {
         Record = CustomerList.Find(delegate(CustomerDataObject Obj) { return(Obj.Id == Record.Id && Obj.Adminid == Record.Adminid); });
         if (!CustomerList.Remove(Record))
         {
             throw new Exception("Unauthorized. No Such CustomerDataObject.");
         }
         return(CustomerList);
     }
     catch
     {
         throw;
     }
 }