public IActionResult EditEvent(Event ev)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("EditEvent"));
            }
            else
            {
                int    res = 0;
                string update;

                if (ev.document != null) //files
                {
                    string    select  = @"SELECT * FROM Events WHERE event_id={0}";
                    DataTable ds      = DBUtl.GetTable(select, ev.event_id);
                    var       docName = ds.Rows[0][ds.Columns.Count - 6].ToString();
                    //delete existing files
                    if (ValidUtl.CheckIfEmpty(docName) == false)
                    {
                        string remainingStr       = docName;
                        string fullpath           = "";
                        int    detectNextLine     = docName.IndexOf("\n");
                        int    detectLastNextLine = docName.LastIndexOf("\n");
                        string docs = "";
                        if (detectNextLine == -1) // 1 file
                        {
                            fullpath = Path.Combine(_env.WebRootPath, "file/" + docName);
                            System.IO.File.Delete(fullpath);
                        }    // working
                        else // >2 files
                        {
                            while (detectNextLine != -1)
                            {
                                docs     = remainingStr.Substring(0, detectNextLine);
                                fullpath = Path.Combine(_env.WebRootPath, "file/" + docs);
                                System.IO.File.Delete(fullpath);
                                remainingStr   = remainingStr.Substring(detectNextLine + 1);
                                detectNextLine = remainingStr.IndexOf("\n");
                            }
                            docs     = docName.Substring(detectLastNextLine + 1);
                            fullpath = Path.Combine(_env.WebRootPath, "file/" + docs);
                            System.IO.File.Delete(fullpath);
                        }
                    }
                    //upload file
                    string fileNames = "";
                    for (int i = 0; i < ev.document.Length; i++)
                    {
                        string docfilename = DoPhotoUpload(ev.document[i]);
                        if (i == 0)
                        {
                            fileNames = fileNames + docfilename;
                        }

                        else
                        {
                            fileNames = fileNames + "\n" + docfilename;
                        }
                    }
                    //check if event is repeated
                    if (ev.repeat == "No")
                    {
                        update =
                            @"UPDATE Events
                    SET event_name='{1}', 
                        event_description='{2}', venue='{3}', category='{4}', start_dt='{5:yyyy-MM-dd HH:mm}', end_dt='{6:yyyy-MM-dd HH:mm}', docName='{7}', CompanyType ={8} 
                  WHERE event_id='{0}'";
                        res = DBUtl.ExecSQL(update, ev.event_id, ev.event_name, ev.event_description, ev.venue, ev.category,
                                            ev.start_dt, ev.end_dt, fileNames, ev.CompanyType);
                    }
                    else
                    {
                        string eventName = ev.event_name.Substring(0, ev.event_name.Length - 3);
                        update =
                            @"UPDATE Events
                    SET event_name='{1}', 
                        event_description='{2}', venue='{3}', category='{4}', start_dt='{5:yyyy-MM-dd HH:mm}', end_dt='{6:yyyy-MM-dd HH:mm}', CompanyType ={7} 
                  WHERE event_id='{0}'";
                        res = DBUtl.ExecSQL(update, ev.event_id, ev.event_name, ev.event_description, ev.venue, ev.category,
                                            ev.start_dt, ev.end_dt, ev.CompanyType);
                        string update2 =
                            @"UPDATE Events SET docName='{1}' WHERE event_name LIKE '{0}%'";
                        res = DBUtl.ExecSQL(update2, eventName, fileNames);
                    }

                    /*
                     * update =
                     * @"UPDATE Events
                     * SET event_name='{1}',
                     *  event_description='{2}', venue='{3}', category='{4}', start_dt='{5:yyyy-MM-dd HH:mm}', end_dt='{6:yyyy-MM-dd HH:mm}', docName='{7}', CompanyType ={8}
                     * WHERE event_id='{0}'";
                     * res = DBUtl.ExecSQL(update, ev.event_id, ev.event_name, ev.event_description, ev.venue, ev.category,
                     *                             ev.start_dt, ev.end_dt, fileNames, ev.CompanyType);
                     */
                }
                else
                {
                    update =
                        @"UPDATE Events
                    SET event_name='{1}', 
                        event_description='{2}', venue='{3}', category='{4}', start_dt='{5:yyyy-MM-dd HH:mm}', end_dt='{6:yyyy-MM-dd HH:mm}', CompanyType ={7}
                  WHERE event_id='{0}'";
                    res = DBUtl.ExecSQL(update, ev.event_id, ev.event_name, ev.event_description, ev.venue, ev.category,
                                        ev.start_dt, ev.end_dt, ev.CompanyType);
                }

                if (res == 1)
                {
                    TempData["Message"] = "Event Updated";
                    TempData["MsgType"] = "success";
                }
                else
                {
                    TempData["Message"] = DBUtl.DB_Message;
                    TempData["MsgType"] = "danger";
                }

                return(RedirectToAction("EventList"));
            }
        }
        public IActionResult DeleteEvent(int id)
        {
            string    select = @"SELECT * FROM Events WHERE event_id={0}";
            DataTable ds     = DBUtl.GetTable(select, id);

            if (ds.Rows.Count != 1)
            {
                TempData["Message"] = "Performance does not exist";
                TempData["MsgType"] = "warning";
            }
            else
            {
                var docName = ds.Rows[0][ds.Columns.Count - 6].ToString();
                if (ValidUtl.CheckIfEmpty(docName) == false)
                {
                    string remainingStr       = docName;
                    string fullpath           = "";
                    int    detectNextLine     = docName.IndexOf("\n");
                    int    detectLastNextLine = docName.LastIndexOf("\n");
                    string docs = "";
                    if (detectNextLine == -1) // 1 file
                    {
                        fullpath = Path.Combine(_env.WebRootPath, "file/" + docName);
                        System.IO.File.Delete(fullpath);
                    }
                    else // >2 files
                    {
                        while (detectNextLine != -1)
                        {
                            docs     = remainingStr.Substring(0, detectNextLine);
                            fullpath = Path.Combine(_env.WebRootPath, "file/" + docs);
                            System.IO.File.Delete(fullpath);
                            remainingStr   = remainingStr.Substring(detectNextLine + 1);
                            detectNextLine = remainingStr.IndexOf("\n");
                        }
                        docs     = docName.Substring(detectLastNextLine + 1);
                        fullpath = Path.Combine(_env.WebRootPath, "file/" + docs);
                        System.IO.File.Delete(fullpath);
                    }
                }
                string nameEventDB = ds.Rows[0][ds.Columns[1]].ToString();
                string eventName   = nameEventDB.Substring(0, nameEventDB.Length - 3);
                string delete      = "DELETE FROM Events WHERE event_name LIKE '{0}%'";
                int    res         = DBUtl.ExecSQL(delete, eventName);

                //send email select string

                if (res == 1)
                {
                    TempData["Message"] = "Event Deleted";
                    TempData["MsgType"] = "success";

                    /*
                     * //send email
                     * string email = "*****@*****.**";
                     * string subject = "Deletion of event";
                     * string template = @"Hi {0},
                     *         <p>{1}</p>
                     *         <p>Your redemption code for free gift is NOTHING.</p>
                     *       Marketing Manager";
                     * string body = String.Format(template, "Qistina", "Yayo");
                     * string result;
                     * if (EmailUtl.SendEmail(email, subject, body, out result))
                     * {
                     *  ViewData["Message"] = "Email Successfully Sent";
                     *  ViewData["MsgType"] = "success";
                     * }
                     * else
                     * {
                     *  ViewData["Message"] = result;
                     *  ViewData["MsgType"] = "warning";
                     * }*/
                }
                else
                {
                    TempData["Message"] = DBUtl.DB_Message;
                    TempData["MsgType"] = "danger";
                }
            }
            return(RedirectToAction("EventList"));
        }