// DELETE: api/PartType/5
        public string Delete(int id)
        {
            try
            {
                db.Part_Supplier.RemoveRange(db.Part_Supplier.Where(x => x.Part_Type_ID == id));
                db.Recipes.RemoveRange(db.Recipes.Where(x => x.Part_Type_ID == id));
                db.Machine_Part.RemoveRange(db.Machine_Part.Where(x => x.Part_Type_ID == id));
                db.Manual_Labour_Type_Part.RemoveRange(db.Manual_Labour_Type_Part.Where(x => x.Part_Type_ID == id));
                db.Part_Blueprint.RemoveRange(db.Part_Blueprint.Where(x => x.Part_Type_ID == id));

                var itemToRemove = db.Part_Type.SingleOrDefault(x => x.Part_Type_ID == id);

                if (itemToRemove != null)
                {
                    db.Part_Type.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Part Type has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartTypeController DELETE");
                return("false|The Part Type is in use and cannot be removed from the system.");
            }
        }
Example #2
0
        public static bool SendEmail(string to, string subject, string body)
        {
            try
            {
                SmtpClient client = new SmtpClient();
                client.Port                  = 587;
                client.Host                  = "smtp.gmail.com";
                client.EnableSsl             = true;
                client.Timeout               = 10000;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "Winning01");

                MailMessage mm = new MailMessage("*****@*****.**", to, subject, body);
                mm.BodyEncoding = UTF8Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

                client.Send(mm);
                return(true);
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "Email");
                return(false);
            }
        }
Example #3
0
 // GET: api/EmployeeType/5
 public string Get(int id)
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             employee_types =
                 from p in db.Employee_Type
                 orderby p.Name
                 where p.Employee_Type_ID == id
                 select new
             {
                 Employee_Type_ID = p.Employee_Type_ID,
                 Name             = p.Name,
                 Description      = p.Description,
                 access           = from d in db.Access_Employee_Type
                                    orderby d.Employee_Type_ID
                                    where d.Employee_Type_ID == id
                                    select new
                 {
                     Access_ID = d.Access_ID,
                     access    = d.Acess
                 }
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "EmployeeTypeController GET ID");
         return("false|Failed to retrieve Employee Category.");
     }
 }
 // GET: api/Access
 public string Get()
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             access =
                 from p in db.Accesses
                 orderby p.Access_ID
                 select new
             {
                 ID      = p.Access_ID,
                 UC_Name = p.Name,
                 access  = false,
                 href    = p.href
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "AccessController GET");
         return("false|Failed to retrieve Access categories.");
     }
 }
 // GET: api/PartStatus/5
 public string Get(int id)
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             part_statuses =
                 from p in db.Part_Status
                 orderby p.Name
                 where p.Part_Status_ID == id
                 select new
             {
                 Part_Status_ID = p.Part_Status_ID,
                 Name           = p.Name,
                 Description    = p.Description
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "PartStatusController GET ID");
         return("false|Failed to retrieve Part Statuses.");
     }
 }
Example #6
0
        // POST: api/EmployeeType
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Employee_Type type = new Employee_Type();

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

                int key = db.Employee_Type.Count() == 0 ? 1 : (from t in db.Employee_Type
                                                               orderby t.Employee_Type_ID descending
                                                               select t.Employee_Type_ID).First() + 1;

                type.Employee_Type_ID = key;
                type.Name             = (string)empType["name"];
                type.Description      = (string)empType["description"];

                JArray access = (JArray)empType["access"];

                //Insert the access levels for this emp type
                foreach (JObject aa in access)
                {
                    bool flag = (bool)aa["access"];

                    int a_ID = (int)aa["ID"];
                    Model.Access_Employee_Type aet = new Access_Employee_Type();
                    aet.Access_ID        = a_ID;
                    aet.Acess            = flag;
                    aet.Employee_Type_ID = key;

                    db.Access_Employee_Type.Add(aet);
                }

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

                if ((from t in db.Employee_Type
                     where t.Name == type.Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Employee Category already exists on the system.";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Employee_Type.Add(type);
                db.SaveChanges();
                return("true|Employee Category  #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "EmployeeTypeController POST");
                return("false|An error has occured adding the Employee Category to the system.");
            }
        }
 // GET: api/ManualLabour/5
 public string Get(int id)
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             manual_labour_types =
                 from p in db.Manual_Labour_Type
                 orderby p.Name
                 where p.Manual_Labour_Type_ID == id
                 select new
             {
                 Manual_Labour_Type_ID = p.Manual_Labour_Type_ID,
                 Name           = p.Name,
                 Description    = p.Description,
                 Duration       = p.Duration,
                 Sub_Contractor = p.Sub_Contractor
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "ManualLabourController GET ID");
         return("false|Failed to retrieve Manual Labour Type.");
     }
 }
        public string Get()
        {
            try
            {
                sqlcon.ConnectionString = "Data Source=localhost;Initial Catalog=Proteus;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
                sqlcon.Open();
                string completePath = HttpContext.Current.Server.MapPath("~/Backup/") + "backup.bak";

                sqlcmd = new SqlCommand("ALTER DATABASE Proteus SET SINGLE_USER WITH ROLLBACK IMMEDIATE", sqlcon);
                sqlcmd.ExecuteNonQuery();

                //string command = "RESTORE DATABASE B FROM DISK = '" + completePath + "'" +
                //                    "WITH MOVE 'DataFileLogicalName' TO 'C:\SQL Directory\DATA\B.mdf',"+
                //                    "MOVE 'LogFileLogicalName' TO 'C:\SQL Directory\DATA\B.ldf',"+
                //                    "REPLACE";

                sqlcmd = new SqlCommand("Restore database UsersDB from disk='" + completePath + "' ", sqlcon);
                sqlcmd.ExecuteNonQuery();

                sqlcmd = new SqlCommand("ALTER DATABASE Proteus SET MULTI_USER", sqlcon);
                sqlcmd.ExecuteNonQuery();



                return("true|Databas has been restored.");
            }
            catch (Exception ex)
            {
                ExceptionLog.LogException(ex, "Restore");
                return("false|Error during restore of database!|" + ex.ToString());
            }
        }
        // PUT: api/Part/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Part part = new Part();
                part = (from p in db.Parts
                        where p.Part_ID == id
                        select p).First();

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

                part.Part_Serial    = (string)partStatusDetails["Part_Serial"];
                part.Part_Status_ID = (int)partStatusDetails["Part_Status_ID"];
                part.Cost_Price     = (decimal)partStatusDetails["Cost_Price"];
                part.Part_Type_ID   = (int)partStatusDetails["Part_Type_ID"];

                db.SaveChanges();
                return("true|Part successfully updated on the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartController PUT");
                return("false|An error has occured updating the Part on the system.");
            }
        }
        // GET: api/Part/5
        public string Get(int id)
        {
            try
            {
                JObject result = JObject.FromObject(new
                {
                    parts =
                        from p in db.Parts
                        where p.Part_ID == id
                        select new
                    {
                        Part_ID        = p.Part_ID,
                        Part_Serial    = p.Part_Serial,
                        Part_Status_ID = p.Part_Status_ID,
                        Date_Added     = p.Date_Added,
                        Cost_Price     = p.Cost_Price,
                        Part_Stage     = p.Part_Stage,
                        Part_Type_ID   = p.Part_Type_ID,

                        Part_Type_Name          = p.Part_Type.Name,
                        Part_Type_Abbreviation  = p.Part_Type.Abbreviation,
                        Part_Type_Dimension     = p.Part_Type.Dimension,
                        Part_Type_Selling_Price = p.Part_Type.Selling_Price,
                        Part_Type_Description   = p.Part_Type.Description
                    }
                });
                return("true|" + result.ToString());
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartController GET ID");
                return("false|Failed to retrieve Part.");
            }
        }
        // POST: api/Part
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Part part = new Model.Part();

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

                int key = db.Parts.Count() == 0 ? 1 : (from t in db.Parts
                                                       orderby t.Part_ID descending
                                                       select t.Part_ID).First() + 1;

                part.Part_ID        = key;
                part.Part_Serial    = (string)partStatusDetails["Part_Serial"];
                part.Part_Status_ID = (int)partStatusDetails["Part_Status_ID"];
                part.Date_Added     = DateTime.Now;
                part.Cost_Price     = (decimal)partStatusDetails["Cost_Price"];
                part.Part_Stage     = (int)partStatusDetails["Part_Stage"];
                part.Parent_ID      = 0;
                part.Part_Type_ID   = (int)partStatusDetails["Part_Type_ID"];

                db.Parts.Add(part);
                db.SaveChanges();
                return("true|Part #" + key + " successfully added to system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartController POST");
                return("false|An error has occured adding the Part to the system.");
            }
        }
 // GET: api/RawMaterial
 public string Get()
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             raw_materials =
                 from p in db.Raw_Material
                 orderby p.Name
                 select new
             {
                 Raw_Material_ID         = p.Raw_Material_ID,
                 Name                    = p.Name,
                 Description             = p.Description,
                 Minimum_Stock_Instances = p.Minimum_Stock_Instances,
                 Raw_Material_Suppliers  =
                     from d in db.Raw_Material_Supplier
                     where d.Raw_Material_ID == p.Raw_Material_ID
                     select new
                 {
                     Supplier_ID = d.Supplier_ID,
                     Is_Prefered = d.Is_Prefered,
                     unit_price  = d.unit_price,
                     Name        = d.Supplier.Name
                 }
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "RawMaterialController GET");
         return("false|Failed to retrieve Raw Materials.");
     }
 }
 // GET: api/Machine/5
 public string Get(int id)
 {
     try
     {
         JObject result = JObject.FromObject(new
         {
             machines =
                 from p in db.Machines
                 orderby p.Name
                 where p.Machine_ID == id
                 select new
             {
                 Machine_ID     = p.Machine_ID,
                 Name           = p.Name,
                 Manufacturer   = p.Manufacturer,
                 Model          = p.Model,
                 Price_Per_Hour = p.Price_Per_Hour,
                 Run_Time       = p.Run_Time
             }
         });
         return("true|" + result.ToString());
     }
     catch (Exception e)
     {
         ExceptionLog.LogException(e, "MachineController GET ID");
         return("false|Failed to retrieve Machine.");
     }
 }
        // POST: api/RawMaterial
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Raw_Material raw = new Model.Raw_Material();

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

                JObject rawDetails  = (JObject)json["raw"];
                JArray  suppDetails = (JArray)json["suppliers"];

                int key = db.Raw_Material.Count() == 0 ? 1 : (from t in db.Raw_Material
                                                              orderby t.Raw_Material_ID descending
                                                              select t.Raw_Material_ID).First() + 1;

                raw.Raw_Material_ID         = key;
                raw.Name                    = (string)rawDetails["Name"];
                raw.Description             = (string)rawDetails["Description"];
                raw.Minimum_Stock_Instances = (int)rawDetails["Minimum_Stock_Instances"];

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

                if ((from t in db.Raw_Material
                     where t.Name == raw.Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Raw Material name entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Raw_Material.Add(raw);

                foreach (JObject supplier in suppDetails)
                {
                    Raw_Material_Supplier rms = new Raw_Material_Supplier();
                    rms.Raw_Material_ID = key;
                    rms.Supplier_ID     = (int)supplier["Supplier_ID"];
                    rms.Is_Prefered     = Convert.ToBoolean(supplier["Is_Prefered"]);
                    rms.unit_price      = (decimal)supplier["unit_price"];

                    db.Raw_Material_Supplier.Add(rms);
                }

                db.SaveChanges();
                return("true|Raw Material #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "RawMaterialController POST");
                return("false|An error has occured adding the Raw Material to the system.");
            }
        }
Example #15
0
        // PUT: api/EmployeeType/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Employee_Type type = new Employee_Type();
                type = (from p in db.Employee_Type
                        where p.Employee_Type_ID == id
                        select p).First();

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

                type.Name        = (string)empType["name"];
                type.Description = (string)empType["description"];

                db.Access_Employee_Type.RemoveRange(db.Access_Employee_Type.Where(x => x.Employee_Type_ID == id));
                JArray access = (JArray)empType["access"];

                //Insert the access levels for this emp type
                foreach (JObject aa in access)
                {
                    bool flag = (bool)aa["access"];

                    int a_ID = (int)aa["ID"];
                    Model.Access_Employee_Type aet = new Access_Employee_Type();
                    aet.Access_ID        = a_ID;
                    aet.Acess            = flag;
                    aet.Employee_Type_ID = id;

                    db.Access_Employee_Type.Add(aet);
                }

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

                if ((from t in db.Employee_Type
                     where t.Name == type.Name && t.Employee_Type_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Employee Category already exists on the system.";
                }

                if (error)
                {
                    return(errorString);
                }

                db.SaveChanges();
                return("true|Employee Category successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "EmployeeTypeController PUT");
                return("false|An error has occured updating the Employee Category on the system.");
            }
        }
Example #16
0
        // GET: api/Customer/5
        public string Get(int id)
        {
            try
            {
                JObject result = JObject.FromObject(new
                {
                    clients =
                        from p in db.Clients
                        where p.Client_ID == id
                        orderby p.Name
                        select new
                    {
                        Client_ID                = p.Client_ID,
                        Name                     = p.Name,
                        Address                  = p.Address,
                        City                     = p.City,
                        Zip                      = p.Zip,
                        Overdue_Payment          = p.Overdue_Payment,
                        Vat_Number               = p.Vat_Number,
                        Account_Name             = p.Account_Name,
                        Contract_Discount_Rate   = p.Contract_Discount_Rate,
                        Client_Status            = p.Client_Status,
                        Province_ID              = p.Province_ID,
                        Settlement_Discount_Rate = p.Settlement_Discount_Rate,

                        contact_details =
                            from d in db.Client_Contact_Person_Detail
                            where d.Client_ID == p.Client_ID
                            orderby d.Name
                            select new
                        {
                            Contact_ID      = d.Contact_ID,
                            Name            = d.Name,
                            Number          = d.Number,
                            Job_Description = d.Job_Description,
                            Email_Address   = d.Email_Address
                        },

                        part_discounts =
                            from pd in db.Client_Discount_Rate
                            where pd.Client_ID == p.Client_ID
                            select new
                        {
                            Discount_Rate          = pd.Discount_Rate,
                            Part_Type_ID           = pd.Part_Type_ID,
                            Part_Type_Name         = pd.Part_Type.Name,
                            Part_Type_Abbreviation = pd.Part_Type.Abbreviation
                        }
                    }
                });
                return("true|" + result.ToString());
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "CustomerController GET ID");
                return("false|Failed to retrieve Customer.");
            }
        }
        // PUT: api/RawMaterial/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Raw_Material raw = new Raw_Material();
                raw = (from p in db.Raw_Material
                       where p.Raw_Material_ID == id
                       select p).First();

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

                JObject rawDetails  = (JObject)json["raw"];
                JArray  suppDetails = (JArray)json["suppliers"];

                raw.Name                    = (string)rawDetails["Name"];
                raw.Description             = (string)rawDetails["Description"];
                raw.Minimum_Stock_Instances = (int)rawDetails["Minimum_Stock_Instances"];

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

                if ((from t in db.Raw_Material
                     where t.Name == raw.Name && t.Raw_Material_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Raw Material name entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Raw_Material_Supplier.RemoveRange(db.Raw_Material_Supplier.Where(x => x.Raw_Material_ID == id));

                foreach (JObject supplier in suppDetails)
                {
                    Raw_Material_Supplier rms = new Raw_Material_Supplier();
                    rms.Raw_Material_ID = id;
                    rms.Supplier_ID     = (int)supplier["Supplier_ID"];
                    rms.Is_Prefered     = Convert.ToBoolean(supplier["Is_Prefered"]);
                    rms.unit_price      = (decimal)supplier["unit_price"];

                    db.Raw_Material_Supplier.Add(rms);
                }

                db.SaveChanges();
                return("true|Raw Material successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "RawMaterialController PUT");
                return("false|An error has occured updating the Raw Material on the system.");
            }
        }
        // POST: api/Machine
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Machine mach = new Model.Machine();

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

                int key = db.Machines.Count() == 0 ? 1 : (from t in db.Machines
                                                          orderby t.Machine_ID descending
                                                          select t.Machine_ID).First() + 1;

                mach.Machine_ID     = key;
                mach.Name           = (string)machineDetails["Name"];
                mach.Manufacturer   = (string)machineDetails["Manufacturer"];
                mach.Model          = (string)machineDetails["Model"];
                mach.Price_Per_Hour = (decimal)machineDetails["Price_Per_Hour"];
                mach.Run_Time       = (int)machineDetails["Run_Time"];

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

                if ((from t in db.Machines
                     where t.Manufacturer == mach.Manufacturer && t.Model == mach.Model
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Machine manufacturer and model entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Machines.Add(mach);
                db.SaveChanges();

                return("true|Machine  #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "MachineController POST");
                return("false|An error has occured adding the Machine to the system.");
            }
        }
        // POST: api/ManualLabour
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Manual_Labour_Type mlt = new Model.Manual_Labour_Type();

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

                int key = db.Manual_Labour_Type.Count() == 0 ? 1 : (from t in db.Manual_Labour_Type
                                                                    orderby t.Manual_Labour_Type_ID descending
                                                                    select t.Manual_Labour_Type_ID).First() + 1;

                mlt.Manual_Labour_Type_ID = key;

                mlt.Name           = (string)json["Name"];
                mlt.Description    = (string)json["Description"];
                mlt.Duration       = (int)json["Duration"];
                mlt.Sub_Contractor = Convert.ToBoolean((string)json["Sub_Contractor"]);

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

                if ((from t in db.Manual_Labour_Type
                     where t.Name == mlt.Name
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Manual Labour Type name entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.Manual_Labour_Type.Add(mlt);

                db.SaveChanges();
                return("true|Manual Labour Type #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "ManualLabourController POST");
                return("false|An error has occured adding the Manual Labour Type to the system.");
            }
        }
        // PUT: api/Machine/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Machine mach = new Machine();

                mach = (from p in db.Machines
                        where p.Machine_ID == id
                        select p).First();

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

                mach.Name           = (string)machineDetails["Name"];
                mach.Manufacturer   = (string)machineDetails["Manufacturer"];
                mach.Model          = (string)machineDetails["Model"];
                mach.Price_Per_Hour = (decimal)machineDetails["Price_Per_Hour"];
                mach.Run_Time       = (int)machineDetails["Run_Time"];

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

                if ((from t in db.Machines
                     where (t.Manufacturer == mach.Manufacturer && t.Model == mach.Model) && t.Machine_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Machine manufacturer and model entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.SaveChanges();
                return("true|Machine successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "MachineController PUT");
                return("false|An error has occured updating the Machine on the system.");
            }
        }
        // DELETE: api/ManualLabour/5
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Manual_Labour_Type.SingleOrDefault(x => x.Manual_Labour_Type_ID == id);
                if (itemToRemove != null)
                {
                    db.Manual_Labour_Type.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Manual Labour Type has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "ManualLabourController DELETE");
                return("false|The Manual Labour Type is in use and cannot be removed from the system.");
            }
        }
        // DELETE: api/Part/5
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Parts.SingleOrDefault(x => x.Part_ID == id);
                if (itemToRemove != null)
                {
                    db.Parts.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Part has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartController DELETE");
                return("false|The Part is in use and cannot be removed from the system.");
            }
        }
        // POST: api/PartStatus
        public string Post(HttpRequestMessage value)
        {
            try
            {
                Model.Part_Status ps = new Model.Part_Status();

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

                int key = db.Part_Status.Count() == 0 ? 1 : (from t in db.Part_Status
                                                             orderby t.Part_Status_ID descending
                                                             select t.Part_Status_ID).First() + 1;

                ps.Part_Status_ID = key;
                ps.Name           = (string)partStatusDetails["Name"];
                ps.Description    = (string)partStatusDetails["Description"];

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

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

                if (error)
                {
                    return(errorString);
                }

                db.Part_Status.Add(ps);
                db.SaveChanges();
                return("true|Part Status #" + key + " successfully added.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartStatusController POST");
                return("false|An error has occured adding the Part Status to the system.");
            }
        }
        public string back_up()
        {
            try
            {
                sqlcon.ConnectionString = "Data Source=localhost;Initial Catalog=Proteus;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework";
                string completePath = HttpContext.Current.Server.MapPath("~/Backup/");

                sqlcon.Open();
                sqlcmd = new SqlCommand("backup database Proteus to disk='" + completePath + "backup.Bak'", sqlcon);
                sqlcmd.ExecuteNonQuery();

                return("true|Database has been sucessfully backed up.");
            }
            catch (Exception ex)
            {
                ExceptionLog.LogException(ex, "Backup");
                return("false|Error during backup of database!|");// + ex.ToString();
            }
        }
        // PUT: api/ManualLabour/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                Manual_Labour_Type mlt = new Manual_Labour_Type();
                mlt = (from p in db.Manual_Labour_Type
                       where p.Manual_Labour_Type_ID == id
                       select p).First();

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

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

                if ((from t in db.Manual_Labour_Type
                     where t.Name == mlt.Name && t.Manual_Labour_Type_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Manual Labour Type name entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                mlt.Name           = (string)json["Name"];
                mlt.Description    = (string)json["Description"];
                mlt.Duration       = (int)json["Duration"];
                mlt.Sub_Contractor = Convert.ToBoolean((string)json["Sub_Contractor"]);

                db.SaveChanges();
                return("true|Manual Labour Type successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "ManualLabourController PUT");
                return("false|An error has occured updating the Manual Labour Type on the system.");
            }
        }
        // DELETE: api/RawMaterial/5
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Raw_Material.SingleOrDefault(x => x.Raw_Material_ID == id);
                db.Raw_Material_Supplier.RemoveRange(db.Raw_Material_Supplier.Where(x => x.Raw_Material_ID == id));
                if (itemToRemove != null)
                {
                    db.Raw_Material.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Raw Material has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "RawMaterialController DELETE");
                return("false|The Raw Material is in use and cannot be removed from the system.");
            }
        }
Example #27
0
        // DELETE: api/EmployeeType/5
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Employee_Type.SingleOrDefault(x => x.Employee_Type_ID == id);
                if (itemToRemove != null)
                {
                    db.Access_Employee_Type.RemoveRange(db.Access_Employee_Type.Where(x => x.Employee_Type_ID == id));
                    db.Employee_Type.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Employee Category has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "EmployeeTypeController DELETE");
                return("false|The Employee Category is in use and cannot be removed from the system.");
            }
        }
Example #28
0
        // DELETE: api/Customer/5
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Clients.SingleOrDefault(x => x.Client_ID == id);
                db.Client_Contact_Person_Detail.RemoveRange(db.Client_Contact_Person_Detail.Where(x => x.Client_ID == id));
                db.Client_Discount_Rate.RemoveRange(db.Client_Discount_Rate.Where(x => x.Client_ID == id));
                if (itemToRemove != null)
                {
                    db.Clients.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Customer has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "CustomerController DELETE");
                return("false|The Customer is in use and cannot be removed from the system.");
            }
        }
        // PUT: api/PartStatus/5
        public string Put(int id, HttpRequestMessage value)
        {
            try
            {
                string  message           = HttpContext.Current.Server.UrlDecode(value.Content.ReadAsStringAsync().Result).Substring(5);
                JObject partStatusDetails = JObject.Parse(message);

                Model.Part_Status ps = new Model.Part_Status();
                ps = (from p in db.Part_Status
                      where p.Part_Status_ID == id
                      select p).First();

                ps.Name        = (string)partStatusDetails["Name"];
                ps.Description = (string)partStatusDetails["Description"];

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

                if ((from t in db.Part_Status
                     where t.Name == ps.Name && t.Part_Status_ID != id
                     select t).Count() != 0)
                {
                    error        = true;
                    errorString += "The Part Status entered already exists on the system. ";
                }

                if (error)
                {
                    return(errorString);
                }

                db.SaveChanges();
                return("true|Part Status successfully updated.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "PartStatus PUT");
                return("false|An error has occured adding the Part Status to the system.");
            }
        }
        // DELETE: api/Employee/5 Delete function
        public string Delete(int id)
        {
            try
            {
                var itemToRemove = db.Employees.SingleOrDefault(x => x.Employee_ID == id);
                itemToRemove.Machines.Clear();
                itemToRemove.Manual_Labour_Type.Clear();
                if (itemToRemove != null)
                {
                    db.Employee_Photo.RemoveRange(db.Employee_Photo.Where(x => x.Employee_ID == id));
                    db.Employees.Remove(itemToRemove);
                    db.SaveChanges();
                }

                return("true|The Employee has successfully been removed from the system.");
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e, "EmployeeController DELETE");
                return("false|The Employee is in use and cannot be removed from the system.");
            }
        }