Ejemplo n.º 1
0
        public ActionResult CreateAction(ActionTableModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                tbl_actions tbl = new tbl_actions();
                tbl.Controller = model.Controller;
                tbl.Value      = model.Value;
                tbl.Text       = model.Text;
                Kdb.tbl_actions.Add(tbl);
                Kdb.SaveChanges();
            }

            return(RedirectToAction("ListAction", "Misc"));
        }
Ejemplo n.º 2
0
        public ActionResult AddActions(string empno, string actionitemcode, HttpPostedFileBase imagefile, string remarks = "", string requestforreview = "")
        {
            string actioncode  = get_acode();
            string actionimage = "";

            //////////////////////
            if (imagefile != null)
            {
                if (imagefile.ContentLength > 0)
                {
                    try
                    {
                        tbl_images im   = new tbl_images();
                        string     path = System.IO.Path.Combine(Server.MapPath("~/fileImages"), System.IO.Path.GetFileName(imagefile.FileName));
                        path = Server.MapPath("~/fileImages/" + actionitemcode + "/" + actioncode);

                        if (!Directory.Exists(path))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(path);
                        }

                        //var im = new tbl_images();
                        //db.images.Add(im);
                        string ext         = System.IO.Path.GetExtension(imagefile.FileName);
                        string newfilename = actioncode;
                        string tosave      = path + "/" + newfilename + ext;
                        int    i           = 0;
                        while (System.IO.File.Exists(tosave))
                        {
                            i++;
                            newfilename = actioncode + "_" + i;
                            tosave      = path + "/" + newfilename + ext;
                        }
                        actionimage = actionitemcode + "/" + actioncode + "/" + newfilename + ext;
                        imagefile.SaveAs(tosave);
                        im = new tbl_images(newfilename, actionimage, actionimage);
                        dbi.images.Add(im);
                        dbi.SaveChanges();
                    }
                    catch
                    {
                    }
                }
            }
            ////////////////



            var ac = new tbl_actions();

            ac.remarks      = remarks;
            ac.itemcode     = actionitemcode;
            ac.actioncode   = actioncode;
            ac.actionimage  = actionimage;
            ac.p_actioncode = "00000";

            ac.empno = empno;
            db.d_actions.Add(ac);
            db.SaveChanges();

            //check if request for review
            if (requestforreview == "forreview")
            {
                tbl_dataFindings d_item = db.dataFindings.Single(p => p.itemcode == actionitemcode);
                d_item.status = 2;
                db.SaveChanges();
            }
            // get gi_code || areaincharge
            string gicode = db.dataFindings.Where(s => s.itemcode == actionitemcode).Select(s => s.areaincharge).Single();

            //get list of incharge

            var loi = db.emaildept.Where(s => s.gi_code == gicode).ToList();

            string[] eset;
            eset = new string[loi.Count];
            if (loi.Count > 0)
            {
                int x = 0;
                foreach (var emp in loi)
                {
                    try {
                        string email = curuser.users.Single(p => p.empno == emp.empno).email.ToString();
                        eset[x] = email;
                        x++;
                    }
                    catch (Exception e) { Response.Write(e.Message); }
                }
            }

            // get_emails
            if (eset.Length > 0)
            {
                SendEmail(eset, actionitemcode, remarks);
            }
            return(RedirectToAction("Details", new { @id = actionitemcode }));
        }