Beispiel #1
0
        public String ViewALLCodes()
        {
            AccessionCodes ac    = new AccessionCodes(db);
            String         codes = ac.ViewALLCodes();

            return(codes);
        }
Beispiel #2
0
        public String SearchCode(string code)
        {
            AccessionCodes ac        = new AccessionCodes(db);
            String         locations = ac.SearchCode(code);

            return(locations);
        }
Beispiel #3
0
        public ActionResult AddRemoveCode(string site, string accession, string type, string isTouch = "")
        {
            Regex rgx    = new Regex("[^a-zA-Z0-9,]");
            var   result = db.AccessionCodes                                           //all existing accession codes
                           .Select(o => o.Code);

            List <String> siteCodes = db.AccLoc.Where(o => o.LocCode == site).Select(o => o.AccCode).ToList();
            List <String> touchList = db.AccessionCodes.Where(o => o.IsTouch == "Y").Select(o => o.Code).ToList();

            String[]         codes = rgx.Replace(accession.Trim(), "").Split(',');
            HashSet <String> set   = new HashSet <string>();

            foreach (String s in codes)
            {
                set.Add(s);
            }
            String errorlog = "";

            if (type == "add")
            {
                foreach (String c in set)
                {
                    if (touchList.Contains(c) && isTouch == "")
                    {
                        errorlog += c + " ";
                    }
                }
                if (errorlog == "")
                {
                    string added = "";
                    foreach (String c in set)
                    {
                        added += c + " ";
                        if (!result.Contains(c))
                        {
                            AccessionCodes ac = new AccessionCodes(db);                    //new regular code only if it does not exist
                            ac.Code = c;
                            if (isTouch != "")
                            {
                                ac.IsTouch = "Y";
                            }
                            else
                            {
                                ac.IsTouch = "N";
                            }
                            ac.CreatedAt = DateTime.Now;
                            ac.UpdatedAt = DateTime.Now;
                            //ac.LockVersion = 0;
                            db.AccessionCodes.Add(ac);
                            db.SaveChanges();

                            AccLoc al = new AccLoc(db);                                             //location and code mapping
                            al.LocCode   = site.Trim();
                            al.AccCode   = c;
                            al.CreatedAt = DateTime.Now;
                            al.UpdatedAt = DateTime.Now;
                            //al.LockVersion = 0;
                            db.AccLoc.Add(al);
                            db.SaveChanges();
                        }
                        else if (siteCodes.Contains(c))
                        {
                            if (isTouch == "y")
                            {
                                if (!touchList.Contains(c))
                                {
                                    AccessionCodes acode = db.AccessionCodes.Where(o => o.Code == c).First();
                                    acode.IsTouch = "Y";
                                    db.SaveChanges();
                                }
                            }
                        }
                        else if (!siteCodes.Contains(c))
                        {
                            if (isTouch == "y")
                            {
                                if (!touchList.Contains(c))
                                {
                                    AccessionCodes acode = db.AccessionCodes.Where(o => o.Code == c).First();
                                    acode.IsTouch = "Y";
                                    db.SaveChanges();
                                }
                            }
                            AccLoc al = new AccLoc(db);                                             //location and code mapping
                            al.LocCode   = site.Trim();
                            al.AccCode   = c;
                            al.CreatedAt = DateTime.Now;
                            al.UpdatedAt = DateTime.Now;
                            //al.LockVersion = 0;
                            db.AccLoc.Add(al);
                            db.SaveChanges();
                        }
                    }


                    added = String.Join(",", added.Trim().Split(" "));
                    UserLogs u = new UserLogs(db);
                    u.LogDetails(currentUserID, IPAddress, "Added accession codes: " + added + " at location : " + site);
                }
                else
                {
                    errorlog = String.Join(",", errorlog.Trim().Split(" "));
                    TempData["accession"] = rgx.Replace(accession.Trim(), "");
                    TempData["site"]      = site.Trim();
                    List <Location> lc = db.Location.ToList();
                    TempData["locations"] = lc;
                    ModelState.AddModelError("CustomError", "The following codes are touch codes and must be added as touch codes for this location" + "\n" + errorlog);
                    return(View("AddRemove"));
                }
            }
            else //remove
            {
                string removed = "";
                foreach (String c in set)
                {
                    if (siteCodes.Contains(c))
                    {
                        AccLoc acl = db.AccLoc.Where(o => o.LocCode == site && o.AccCode == c).First();
                        db.Remove(acl);
                        db.SaveChanges();
                        removed += c + " ";
                    }
                }

                removed = String.Join(",", removed.Trim().Split(" "));
                UserLogs u = new UserLogs(db);
                u.LogDetails(currentUserID, IPAddress, "Removed accession codes: " + removed + " at location : " + site);

                //removing the unused codes    NOW HANDLED BY TRIGGER
                //List<String> accLocLeft = db.AccLoc.Select(o => o.AccCode).ToList();
                //List<AccessionCodes> toBeDel = db.AccessionCodes.Where(o => !accLocLeft.Contains(o.Code)).ToList();
                //foreach (AccessionCodes ac in toBeDel)
                //{
                //    db.AccessionCodes.Remove(ac);
                //    db.SaveChanges();
                //}
            }

            TempData["msg"] = "Success";
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #4
0
        public ActionResult AddNewSite(string name, string servername, string path, string code, string status, string diagnostic, string retention, string accession = "", string touch = "")
        {
            //System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@touch");
            System.Diagnostics.Debug.WriteLine(touch + touch == "");
            Regex            rgx         = new Regex("[^a-zA-Z0-9,]");
            HashSet <String> setNonTouch = new HashSet <string>();
            HashSet <String> setTouch    = new HashSet <string>();

            Boolean flag = false;

            if (db.Location.Any(o => o.Code.Trim().Equals(code.Trim(), StringComparison.InvariantCultureIgnoreCase)))
            {
                flag = true;
            }
            List <String> touchList = db.AccessionCodes.Where(o => o.IsTouch == "Y").Select(o => o.Code).ToList();

            //System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@touch"+touchList.ToString());
            if (accession != "" && accession != null)
            {
                String[] nontouchcodes = rgx.Replace(accession.Trim(), "").Split(',');
                //System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@touch" + nontouchcodes.ToString());
                String errorlog = "";
                foreach (String c in nontouchcodes)
                {
                    if (touchList.Contains(c))
                    {
                        //System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@entered");
                        errorlog += c + " ";
                        flag      = true;
                    }
                }
                //System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@touch" + errorlog.ToString());
                if (errorlog != "")
                {
                    errorlog               = String.Join(",", errorlog.Trim().Split(" "));
                    TempData["code"]       = code;
                    TempData["name"]       = name;
                    TempData["servername"] = servername;
                    TempData["path"]       = path;
                    TempData["status"]     = status;
                    TempData["diagnostic"] = diagnostic;
                    TempData["retention"]  = retention;
                    if (accession != "" && accession != null)
                    {
                        TempData["accession"] = rgx.Replace(accession.Trim(), "");
                    }
                    if (touch != "" && touch != null)
                    {
                        TempData["touch"] = rgx.Replace(touch.Trim(), "");
                    }
                    ModelState.AddModelError("CustomError", "The following codes are touch codes and must be added as touch codes for this location" + "\n" + errorlog);
                    return(View("AddNewForm"));
                }
            }



            if (!flag)
            {
                Location l = new Location(db);
                l.Name            = name.Trim();
                l.Server          = servername.Trim();
                l.Path            = path.Trim();
                l.Code            = code.Trim();
                l.Status          = status.Trim();
                l.DiagnosticLevel = Convert.ToInt32(diagnostic);
                l.RetentionPeriod = Convert.ToInt32(retention);
                //l.LockVersion = 0;
                l.CreatedAt         = DateTime.Now;
                l.UpdatedAt         = DateTime.Now;
                l.ConfigFileVersion = 0;
                l.IsFTP             = "N";

                db.Location.Add(l);
                int res = db.SaveChanges();

                if (res > 0)
                {
                    var result = db.AccessionCodes
                                 .Select(o => o.Code);
                    if (accession != "" && accession != null)
                    {
                        String[] codes = rgx.Replace(accession.Trim(), "").Split(',');
                        foreach (String t in codes)
                        {
                            setNonTouch.Add(t);    //removing duplicates
                        }
                        foreach (String c in setNonTouch)
                        {
                            if (!result.Contains(c))
                            {
                                AccessionCodes ac = new AccessionCodes(db);                    //new regular code only if it does not exist
                                ac.Code      = c;
                                ac.IsTouch   = "N";
                                ac.CreatedAt = DateTime.Now;
                                ac.UpdatedAt = DateTime.Now;
                                //ac.LockVersion = 0;
                                db.AccessionCodes.Add(ac);
                                db.SaveChanges();
                            }
                            AccLoc al = new AccLoc(db);                                             //location and code mapping
                            al.LocCode   = code.Trim();
                            al.AccCode   = c;
                            al.CreatedAt = DateTime.Now;
                            al.UpdatedAt = DateTime.Now;
                            //al.LockVersion = 0;
                            db.AccLoc.Add(al);
                            db.SaveChanges();
                        }
                    }
                    if (touch != "" && touch != null)
                    {
                        String[] touchCodes = rgx.Replace(touch.Trim(), "").Split(',');
                        foreach (String t in touchCodes)
                        {
                            setTouch.Add(t);
                        }
                        foreach (String c in setTouch)
                        {
                            if (!result.Contains(c))
                            {
                                AccessionCodes ac = new AccessionCodes(db);          //new touch code
                                ac.Code      = c;
                                ac.IsTouch   = "Y";
                                ac.CreatedAt = DateTime.Now;
                                ac.UpdatedAt = DateTime.Now;
                                // ac.LockVersion = 0;
                                db.AccessionCodes.Add(ac);
                                db.SaveChanges();
                            }
                            else
                            {
                                AccessionCodes old = db.AccessionCodes.Where(o => o.Code == c.Trim()).First();  //update the existing code as touch
                                old.IsTouch   = "Y";
                                old.UpdatedAt = DateTime.Now;
                                db.SaveChanges();
                            }
                            AccLoc al = new AccLoc(db);
                            al.LocCode   = code.Trim();
                            al.AccCode   = c;
                            al.CreatedAt = DateTime.Now;
                            al.UpdatedAt = DateTime.Now;
                            //al.LockVersion = 0;
                            db.AccLoc.Add(al);
                            db.SaveChanges();
                        }
                    }
                }

                UserLogs u = new UserLogs(db);
                u.LogDetails(currentUserID, IPAddress, "Created site: " + l.Name);
                TempData["msg"] = "The site has been added successfully";
                return(RedirectToAction("Index", "Home"));
            }
            TempData["code"]       = code;
            TempData["name"]       = name;
            TempData["servername"] = servername;
            TempData["path"]       = path;
            TempData["status"]     = status;
            TempData["diagnostic"] = diagnostic;
            TempData["retention"]  = retention;
            if (accession != "" && accession != null)
            {
                TempData["accession"] = rgx.Replace(accession.Trim(), "");
            }
            if (touch != "" && touch != null)
            {
                TempData["touch"] = rgx.Replace(touch.Trim(), "");
            }
            ModelState.AddModelError("CustomError", "The Location Already exists. Please change the location code");
            return(View("AddNewForm"));
        }