// GET: api/PartType/5
        public string Get(int id)
        {
            try
            {
                JObject result = JObject.FromObject(new
                {
                    part_types =
                        from p in db.Part_Type
                        orderby p.Name
                        where p.Part_Type_ID == id
                        select new
                    {
                        Part_Type_ID            = p.Part_Type_ID,
                        Abbreviation            = p.Abbreviation,
                        Name                    = p.Name,
                        Description             = p.Description,
                        Selling_Price           = p.Selling_Price,
                        Dimension               = p.Dimension,
                        Minimum_Level           = p.Minimum_Level,
                        Maximum_Level           = p.Maximum_Level,
                        Max_Discount_Rate       = p.Max_Discount_Rate,
                        Manufactured            = p.Manufactured,
                        Average_Completion_Time = p.Average_Completion_Time,
                        Stock_Available         = db.Parts.Where(x => x.Part_Type_ID == id && (x.Part_Status_ID == 3)).Count(),

                        Manual_Labours =
                            from d in db.Manual_Labour_Type_Part
                            where d.Part_Type_ID == p.Part_Type_ID
                            select new
                        {
                            Manual_Labour_Type_ID   = d.Manual_Labour_Type_ID,
                            Manual_Labour_Type_Name = d.Manual_Labour_Type.Name,
                            Stage_In_Manufacturing  = d.Stage_In_Manufacturing
                        },

                        Machines =
                            from d in db.Machine_Part
                            where d.Part_Type_ID == p.Part_Type_ID
                            select new
                        {
                            Machine_ID             = d.Machine_ID,
                            Machine_Name           = d.Machine.Name,
                            Stage_In_Manufacturing = d.Stage_In_Manufacturing
                        },

                        recipe =
                            from d in db.Recipes
                            where d.Part_Type_ID == p.Part_Type_ID
                            select new
                        {
                            Recipe_ID              = d.Recipe_ID,
                            Recipe_Type            = d.Recipe_Type,
                            Quantity_Required      = d.Quantity_Required,
                            Stage_in_Manufacturing = d.Stage_in_Manufacturing,
                            Item_ID   = d.Item_ID,
                            Dimension = d.Dimension
                        },

                        suppliers =
                            from d in db.Part_Supplier
                            where d.Part_Type_ID == p.Part_Type_ID
                            select new
                        {
                            Is_Prefered = d.Is_Prefered,
                            Supplier_ID = d.Supplier_ID,
                            Name        = d.Supplier.Name,
                            unit_price  = d.unit_price
                        },

                        blueprints =
                            from b in db.Part_Blueprint
                            orderby b.Name
                            where b.Part_Type_ID == id
                            select new
                        {
                            Name         = b.Name,
                            Blueprint_ID = b.Blueprint_ID,
                            File_Type    = b.File_Type,
                            Removed      = false
                        }
                    }
                });
                return("true|" + result.ToString());
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartTypeController GET ID");
                return("false|Failed to retrieve Part Type.");
            }
        }
        // PUT: api/PartType/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Model.Part_Type part = new Model.Part_Type();
                part = (from p in db.Part_Type
                        where p.Part_Type_ID == id
                        select p).First();

                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);

                JObject partDetails    = (JObject)json["partType"];
                JArray  suppDetails    = (JArray)json["supplier"];
                JArray  recipeDetails  = (JArray)json["recipe"];
                JArray  manualDetails  = (JArray)json["manual"];
                JArray  machineDetails = (JArray)json["machine"];

                part.Abbreviation            = (string)partDetails["Abbreviation"];
                part.Name                    = (string)partDetails["Name"];
                part.Description             = (string)partDetails["Description"];
                part.Selling_Price           = (decimal)partDetails["Selling_Price"];
                part.Dimension               = (string)partDetails["Dimension"];
                part.Minimum_Level           = (int)partDetails["Minimum_Level"];
                part.Maximum_Level           = (int)partDetails["Maximum_Level"];
                part.Max_Discount_Rate       = (int)partDetails["Max_Discount_Rate"];
                part.Manufactured            = Convert.ToBoolean(Convert.ToInt32(partDetails["Manufactured"]));
                part.Average_Completion_Time = (int)partDetails["Average_Completion_Time"];

                string errorString = "false|";
                bool   error       = false;

                if ((from t in db.Part_Type
                     where t.Name == part.Name && t.Part_Type_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Part Type name entered already exists on the system. ";
                }

                if ((from t in db.Part_Type
                     where t.Abbreviation == part.Abbreviation && t.Part_Type_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Part Type Abbreviation entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Part_Supplier.RemoveRange(db.Part_Supplier.Where(x => x.Part_Type_ID == id));

                foreach (JObject supplier in suppDetails)
                {
                    Part_Supplier ps = new Part_Supplier();
                    ps.Part_Type_ID = id;
                    ps.Supplier_ID  = (int)supplier["Supplier_ID"];
                    ps.Is_Prefered  = Convert.ToBoolean(Convert.ToInt32(supplier["Is_Prefered"]));
                    ps.unit_price   = (decimal)supplier["unit_price"];

                    db.Part_Supplier.Add(ps);
                }

                int recipe_key = db.Recipes.Count() == 0 ? 1 : (from t in db.Recipes
                                                                orderby t.Recipe_ID descending
                                                                select t.Recipe_ID).First() + 1;
                db.Recipes.RemoveRange(db.Recipes.Where(x => x.Part_Type_ID == id));

                int stages  = 0;
                int runtime = 0;

                foreach (JObject item in recipeDetails)
                {
                    Recipe rec = new Recipe();
                    recipe_key++;
                    rec.Recipe_ID              = recipe_key;
                    rec.Part_Type_ID           = id;
                    rec.Stage_in_Manufacturing = (int)item["Stage_in_Manufacturing"];
                    rec.Quantity_Required      = (int)item["Quantity_Required"];
                    rec.Item_ID     = (int)item["resouce_ID"];
                    rec.Recipe_Type = (string)item["Recipe_Type"];
                    rec.Item_Name   = (string)item["Item_Name"];
                    rec.Dimension   = (String)item["Dimension"];
                    stages++;

                    if ((string)item["Recipe_Type"] == "Part Type")
                    {
                        runtime += (from t in db.Part_Type
                                    where t.Part_Type_ID == rec.Item_ID
                                    select t.Average_Completion_Time).First();
                    }

                    db.Recipes.Add(rec);
                }

                db.Manual_Labour_Type_Part.RemoveRange(db.Manual_Labour_Type_Part.Where(x => x.Part_Type_ID == id));
                foreach (JObject manual in manualDetails)
                {
                    Manual_Labour_Type_Part ml = new Manual_Labour_Type_Part();

                    ml.Manual_Labour_Type_ID  = (int)manual["Manual_Labour_Type_ID"];
                    ml.Stage_In_Manufacturing = (int)manual["Stage_In_Manufacturing"];
                    ml.Part_Type_ID           = id;
                    stages++;
                    runtime += (from t in db.Manual_Labour_Type
                                where t.Manual_Labour_Type_ID == ml.Manual_Labour_Type_ID
                                select t.Duration).First();

                    db.Manual_Labour_Type_Part.Add(ml);
                }

                db.Machine_Part.RemoveRange(db.Machine_Part.Where(x => x.Part_Type_ID == id));
                foreach (JObject machine in machineDetails)
                {
                    Machine_Part mach = new Machine_Part();

                    mach.Machine_ID             = (int)machine["Machine_ID"];
                    mach.Stage_In_Manufacturing = (int)machine["Stage_In_Manufacturing"];
                    mach.Part_Type_ID           = id;
                    stages++;
                    runtime += (from t in db.Machines
                                where t.Machine_ID == mach.Machine_ID
                                select t.Run_Time).First();

                    db.Machine_Part.Add(mach);
                }
                part.Number_Of_Stages        = stages;
                part.Average_Completion_Time = runtime;

                db.SaveChanges();
                return("true|Part Type successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartTypeController PUT");
                return("false|An error has occured updating the Part Type on the system.");
            }
        }
Ejemplo n.º 3
0
        // POST: api/Customer
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Client client = new Model.Client();

                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);

                JObject clientDetails  = (JObject)json["client"];
                JArray  partDiscounts  = (JArray)json["discounts"];
                JArray  contactDetails = (JArray)json["contacts"];

                int key = db.Clients.Count() == 0 ? 1 : (from t in db.Clients
                                                         orderby t.Client_ID descending
                                                         select t.Client_ID).First() + 1;
                client.Client_ID                = key;
                client.Name                     = (string)clientDetails["Name"];
                client.Address                  = (string)clientDetails["Address"];
                client.City                     = (string)clientDetails["City"];
                client.Zip                      = (string)clientDetails["Zip"];
                client.Overdue_Payment          = 0;
                client.Vat_Number               = (string)clientDetails["Vat_Number"];
                client.Account_Name             = (string)clientDetails["Account_Name"];
                client.Contract_Discount_Rate   = (int)clientDetails["Contract_Discount_Rate"];
                client.Client_Status            = Convert.ToBoolean(Convert.ToInt32(clientDetails["Client_Status"]));
                client.Province_ID              = (int)clientDetails["Province_ID"];
                client.Settlement_Discount_Rate = (int)clientDetails["Settlement_Discount_Rate"];

                string errorString = "false|";
                bool   error       = false;

                if ((from t in db.Clients
                     where t.Name == client.Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer Name entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Name == client.Vat_Number
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Address == client.Address && t.City == client.City && t.Zip == client.Zip
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer Address entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Vat_Number == client.Vat_Number && client.Vat_Number != ""
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Account_Name == client.Account_Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Clients.Add(client);

                int contact_key = db.Client_Contact_Person_Detail.Count() == 0 ? 1 : (from t in db.Client_Contact_Person_Detail
                                                                                      orderby t.Contact_ID descending
                                                                                      select t.Contact_ID).First() + 1;

                foreach (JObject contact in contactDetails)
                {
                    Client_Contact_Person_Detail ccpd = new Client_Contact_Person_Detail();
                    ccpd.Contact_ID = contact_key;
                    contact_key++;
                    ccpd.Client_ID = key;

                    ccpd.Number          = (string)contact["Number"];
                    ccpd.Name            = (string)contact["Name"];
                    ccpd.Job_Description = (string)contact["Job_Description"];
                    ccpd.Email_Address   = (string)contact["Email_Address"];

                    errorString = "false|";
                    error       = false;

                    if ((from t in db.Client_Contact_Person_Detail
                         where t.Email_Address == ccpd.Email_Address
                         select t).Count() != 0)
                    {
                        error        = true;
                        errorString += "The Customer Contact Email for " + ccpd.Name + " entered already exists on the system. ";
                    }

                    if ((from t in db.Client_Contact_Person_Detail
                         where t.Number == ccpd.Number
                         select t).Count() != 0)
                    {
                        error        = true;
                        errorString += "The Customer Contact Number for " + ccpd.Name + " entered already exists on the system. ";
                    }

                    if (error)
                    {
                        return(errorString);
                    }

                    db.Client_Contact_Person_Detail.Add(ccpd);
                }

                foreach (JObject part in partDiscounts)
                {
                    Client_Discount_Rate cdr = new Client_Discount_Rate();

                    cdr.Client_ID     = key;
                    cdr.Part_Type_ID  = (int)part["Part_Type_ID"];
                    cdr.Discount_Rate = (float)part["Discount_Rate"];

                    db.Client_Discount_Rate.Add(cdr);
                }

                db.SaveChanges();
                return("true|Customer # " + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "CustomerController POST");
                return("false|An error has occured adding the Customer to the system.");
            }
        }
Ejemplo n.º 4
0
        // PUT: api/Customer/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Client client = new Client();
                client = (from p in db.Clients
                          where p.Client_ID == id
                          select p).First();

                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);

                JObject clientDetails  = (JObject)json["client"];
                JArray  partDiscounts  = (JArray)json["discounts"];
                JArray  contactDetails = (JArray)json["contacts"];

                client.Name                     = (string)clientDetails["Name"];
                client.Address                  = (string)clientDetails["Address"];
                client.City                     = (string)clientDetails["City"];
                client.Zip                      = (string)clientDetails["Zip"];
                client.Vat_Number               = (string)clientDetails["Vat_Number"];
                client.Account_Name             = (string)clientDetails["Account_Name"];
                client.Contract_Discount_Rate   = (int)clientDetails["Contract_Discount_Rate"];
                client.Client_Status            = Convert.ToBoolean(Convert.ToInt32(clientDetails["Client_Status"]));
                client.Province_ID              = (int)clientDetails["Province_ID"];
                client.Settlement_Discount_Rate = (int)clientDetails["Settlement_Discount_Rate"];


                string errorString = "false|";
                bool   error       = false;

                if ((from t in db.Clients
                     where t.Name == client.Name && t.Client_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer Name entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Name == client.Vat_Number && t.Client_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where (t.Address == client.Address && t.City == client.City && t.Zip == client.Zip) && t.Client_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer address entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where (t.Vat_Number == client.Vat_Number && client.Vat_Number != "") && t.Client_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if ((from t in db.Clients
                     where t.Account_Name == client.Account_Name && t.Client_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Customer VAT Number entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }


                int contact_id = db.Client_Contact_Person_Detail.Count() == 0 ? 1 : (from t in db.Client_Contact_Person_Detail
                                                                                     orderby t.Contact_ID descending
                                                                                     select t.Contact_ID).First() + 1;
                List <Client_Contact_Person_Detail> clientUpdated = new List <Client_Contact_Person_Detail>();
                foreach (JObject contact in contactDetails)
                {
                    string email = (string)contact["Email_Address"];
                    Client_Contact_Person_Detail ccpd = new Client_Contact_Person_Detail();
                    ccpd = (from p in db.Client_Contact_Person_Detail
                            where p.Email_Address == email
                            select p).FirstOrDefault();

                    if (ccpd != null)
                    {
                        ccpd.Number          = (string)contact["Number"];
                        ccpd.Name            = (string)contact["Name"];
                        ccpd.Job_Description = (string)contact["Job_Description"];
                        ccpd.Email_Address   = (string)contact["Email_Address"];

                        errorString = "false|";
                        error       = false;

                        if ((from t in db.Client_Contact_Person_Detail
                             where t.Email_Address == ccpd.Email_Address && t.Contact_ID != ccpd.Contact_ID
                             select t).Count() != 0)
                        {
                            error        = true;
                            errorString += "The Customer Contact Email for " + ccpd.Name + " entered already exists on the system. ";
                        }

                        if ((from t in db.Client_Contact_Person_Detail
                             where t.Number == ccpd.Number && t.Contact_ID != ccpd.Contact_ID
                             select t).Count() != 0)
                        {
                            error        = true;
                            errorString += "The Customer Contact Number for " + ccpd.Name + " entered already exists on the system. ";
                        }

                        if (error)
                        {
                            return(errorString);
                        }

                        clientUpdated.Add(ccpd);
                    }
                    else
                    {
                        ccpd            = new Client_Contact_Person_Detail();
                        ccpd.Client_ID  = id;
                        ccpd.Contact_ID = contact_id;
                        contact_id++;
                        ccpd.Number          = (string)contact["Number"];
                        ccpd.Name            = (string)contact["Name"];
                        ccpd.Job_Description = (string)contact["Job_Description"];
                        ccpd.Email_Address   = (string)contact["Email_Address"];

                        errorString = "false|";
                        error       = false;

                        if ((from t in db.Client_Contact_Person_Detail
                             where t.Email_Address == ccpd.Email_Address
                             select t).Count() != 0)
                        {
                            error        = true;
                            errorString += "The Customer Contact Email for " + ccpd.Name + " entered already exists on the system. ";
                        }

                        if ((from t in db.Client_Contact_Person_Detail
                             where t.Number == ccpd.Number
                             select t).Count() != 0)
                        {
                            error        = true;
                            errorString += "The Customer Contact Number for " + ccpd.Name + " entered already exists on the system. ";
                        }

                        if (error)
                        {
                            return(errorString);
                        }

                        db.Client_Contact_Person_Detail.Add(ccpd);
                        clientUpdated.Add(ccpd);
                    }
                }

                List <Client_Contact_Person_Detail> clientContacts = new List <Client_Contact_Person_Detail>();
                clientContacts = (from p in db.Client_Contact_Person_Detail
                                  where p.Client_ID == client.Client_ID
                                  select p).ToList();

                foreach (Client_Contact_Person_Detail clientC in clientContacts)
                {
                    if (!clientUpdated.Contains(clientC))
                    {
                        try
                        {
                            var itemToRemove = db.Client_Contact_Person_Detail.SingleOrDefault(x => x.Contact_ID == clientC.Contact_ID);
                            if (itemToRemove != null)
                            {
                                db.Client_Contact_Person_Detail.Remove(itemToRemove);
                                db.SaveChanges();
                            }

                            return("true|The Customer Contact " + clientC.Name + " has successfully been removed from the system.");
                        }
                        catch
                        {
                            return("false|The Customer Contact " + clientC.Name + " is in use and cannot be removed from the system.");
                        }
                    }
                }


                db.Client_Discount_Rate.RemoveRange(db.Client_Discount_Rate.Where(x => x.Client_ID == id));

                foreach (JObject part in partDiscounts)
                {
                    Client_Discount_Rate cdr = new Client_Discount_Rate();

                    cdr.Client_ID     = client.Client_ID;
                    cdr.Part_Type_ID  = (int)part["Part_Type_ID"];
                    cdr.Discount_Rate = (float)part["Discount_Rate"];

                    db.Client_Discount_Rate.Add(cdr);
                }

                db.SaveChanges();
                return("true|Customer successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "CustomerController PUT");
                return("false|An error has occured updating the Customer on the system.");
            }
        }
        // POST: api/SearchEmployee
        public string Post(HttpRequestMessage value)
        {
            try
            {
                string  message = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject json    = JObject.Parse(message);

                string  method   = (string)json["method"];   //Exact, Contains, Similar
                string  criteria = (string)json["criteria"]; //Typed in search value
                string  category = (string)json["category"]; //Name, Description, Access Level
                JObject result   = null;


                if (method == "PS")
                {
                    result = JObject.FromObject(new
                    {
                        employees =
                            from p in db.Employees
                            orderby p.Name
                            where p.Name.Contains(criteria) || p.Surname.Contains(criteria) || p.Email.Contains(criteria) ||
                            p.ID_Number.Contains(criteria) || p.Contact_Number.Contains(criteria)
                            select new
                        {
                            Employee_ID            = p.Employee_ID,
                            Name                   = p.Name,
                            Surname                = p.Surname,
                            ID_Number              = p.ID_Number,
                            Contact_Number         = p.Contact_Number,
                            Password               = p.Password,
                            Salt                   = p.Salt,
                            Username               = p.Username,
                            Email                  = p.Email,
                            Employee_Type_ID       = p.Employee_Type_ID,
                            Gender_ID              = p.Gender_ID,
                            Employee_Status        = p.Employee_Status,
                            Employee_Category_Name = p.Employee_Type.Name,

                            manual_labour = p.Manual_Labour_Type.Select(s => s.Manual_Labour_Type_ID).ToList(),
                            machines      = p.Machines.Select(s => s.Machine_ID).ToList()
                        }
                    });
                }
                if (method == "Exact")
                {
                    if (category == "All")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Name == criteria || p.Surname == criteria || p.Email == criteria ||
                                p.ID_Number == criteria || p.Contact_Number == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Name")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Name == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Surname")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Surname == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Email")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Email == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "IDNumber")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.ID_Number == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "ContactNumber")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Contact_Number == criteria
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                }
                else
                if (method == "Contains")
                {
                    if (category == "All")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Name.Contains(criteria) || p.Surname.Contains(criteria) || p.Email.Contains(criteria) ||
                                p.ID_Number.Contains(criteria) || p.Contact_Number.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Name")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Name.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Surname")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Surname.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "Email")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Email.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "IDNumber")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.ID_Number.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                    else
                    if (category == "ContactNumber")
                    {
                        result = JObject.FromObject(new
                        {
                            employees =
                                from p in db.Employees
                                orderby p.Name
                                where p.Contact_Number.Contains(criteria)
                                select new
                            {
                                Employee_ID            = p.Employee_ID,
                                Name                   = p.Name,
                                Surname                = p.Surname,
                                ID_Number              = p.ID_Number,
                                Contact_Number         = p.Contact_Number,
                                Password               = p.Password,
                                Salt                   = p.Salt,
                                Username               = p.Username,
                                Email                  = p.Email,
                                Employee_Type_ID       = p.Employee_Type_ID,
                                Gender_ID              = p.Gender_ID,
                                Employee_Status        = p.Employee_Status,
                                Employee_Category_Name = p.Employee_Type.Name,

                                manual_labour = p.Manual_Labour_Type.Select(s => s.Name).ToList(),
                                machines      = p.Machines.Select(s => s.Name).ToList()
                            }
                        });
                    }
                }

                return("true|" + result.ToString());
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "SearchEmployeeController");
                return("false|An error has occured searching for Employee on the system.");
            }
        }