public ActionResult Standards(StandardViewModel svm, HttpPostedFileBase inputFile) {
            if (!string.IsNullOrEmpty(svm.Standard.StandardNo)) {
                if (!string.IsNullOrEmpty(svm.Standard.Year)) {
                    if (!string.IsNullOrEmpty(svm.Standard.Revision)) {
                        if (!string.IsNullOrEmpty(svm.Standard.SubjectParam) && !string.IsNullOrEmpty(svm.Standard.Subject)) {
                            try {
                                if (svm.Standard.Subject.Equals("OTHERS")) {
                                    svm.Standard.Subject = svm.OSubject.Trim().ToUpper();
                                    string subjectParam = svm.Standard.SubjectParam;
                                    string strSubject = svm.OSubject.Trim().ToUpper();
                                    if (!string.IsNullOrEmpty(strSubject)) {
                                        string keyName = subjectParam.Equals("EQUIPMENT") ? "StdEquipment" : (subjectParam.Equals("SPARES FOR") ? "StdSpareFor" : string.Empty);
                                        if (keyName != string.Empty) {
                                            string keyValue = strSubject;
                                            AddParam(keyName, keyValue);
                                        }
                                    }
                                    else {
                                        TempData["Error"] = "Please Enter Subject.";
                                    }
                                }
                            }
                            catch (Exception) {
                                TempData["Error"] = "Subject is not added to the Parameter Master.";
                            }
                            if (!string.IsNullOrEmpty(svm.Standard.Type)) {
                                if (svm.Standard.Type.Equals("OTHERS")) {
                                    svm.Standard.Type = svm.OType.Trim().ToUpper();
                                    string strType = svm.OType.Trim().ToUpper();
                                    if (!string.IsNullOrEmpty(strType)) {
                                        string keyName = "StdType";
                                        if (keyName != string.Empty) {
                                            string keyValue = svm.Standard.Type;
                                            AddParam(keyName, keyValue);
                                        }
                                    }
                                    else {
                                        TempData["Error"] = "Please Enter Type.";
                                    }
                                }
                                if (inputFile != null && inputFile.ContentLength > 0) {
                                    if (inputFile.ContentType == "application/pdf") {
                                        Guid FileName = Guid.NewGuid();
                                        svm.Standard.FilePath = "/Uploads/Standards/" + FileName + ".pdf";
                                        string tPath = Path.Combine(Server.MapPath("~/Uploads/Standards/"), FileName + ".pdf");
                                        inputFile.SaveAs(tPath);

                                        svm.Standard.CreatedBy = Request.Cookies["INDMS"]["UserID"];
                                        svm.Standard.CreatedDate = null;

                                        db.Standards.Add(svm.Standard);
                                        db.SaveChanges();

                                        TempData["RowId"] = svm.Standard.Id;
                                        TempData["MSG"] = "Save Successfully";

                                        return RedirectToAction("Standards");
                                    }
                                    else {
                                        TempData["Error"] = "Please Select PDF file only";
                                    }
                                }
                                else {
                                    TempData["Error"] = "Please Select file";
                                }
                            }
                            else {
                                TempData["Error"] = "Please Select Type.";
                            }
                        }
                        else {
                            TempData["Error"] = "Please Select Subject.";
                        }
                    }
                    else {
                        TempData["Error"] = "Please Enter Revision.";
                    }
                }
                else {
                    TempData["Error"] = "Please Enter Year";
                }
            }
            else {
                TempData["Error"] = "Please Enter Standard No.";
            }
            StandardViewModel vm = new StandardViewModel {
                OType = svm.OType,
                OSubject = svm.OSubject,
                Standard = svm.Standard,
                Standards = db.Standards.OrderByDescending(x => x.Id)
            };
            return View(vm);
        }
        public ActionResult StandardEdit(int? id) {
            StandardViewModel m = new StandardViewModel();

            if (id == null) {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            else {
                m.Standard = db.Standards.Find(id);
                if (m.Standard == null) {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                else {
                    m.file = m.Standard.FilePath;
                }
            }
            return View(m);
        }
        public ActionResult StandardEdit(StandardViewModel m, HttpPostedFileBase inputFile) {
            if (!string.IsNullOrEmpty(m.Standard.StandardNo)) {
                if (!string.IsNullOrEmpty(m.Standard.Year)) {
                    if (!string.IsNullOrEmpty(m.Standard.Revision)) {
                        if (!string.IsNullOrEmpty(m.Standard.SubjectParam) && !string.IsNullOrEmpty(m.Standard.Subject)) {
                            try {
                                if (m.Standard.Subject.Equals("OTHERS")) {
                                    m.Standard.Subject = m.OSubject.Trim().ToUpper();
                                    string subjectParam = m.Standard.SubjectParam;
                                    string strSubject = m.OSubject.Trim().ToUpper();
                                    if (!string.IsNullOrEmpty(strSubject)) {
                                        string keyName = subjectParam.Equals("EQUIPMENT") ? "StdEquipment" : (subjectParam.Equals("SPARES FOR") ? "StdSpareFor" : string.Empty);
                                        if (keyName != string.Empty) {
                                            string keyValue = strSubject;
                                            AddParam(keyName, keyValue);
                                        }
                                    }
                                    else {
                                        TempData["Error"] = "Please Enter Subject.";
                                    }
                                }
                            }
                            catch (Exception) {
                                TempData["Error"] = "Subject is not added to the Parameter Master.";
                            }

                            if (!string.IsNullOrEmpty(m.Standard.Type)) {
                                if (m.Standard.Type.Equals("OTHERS")) {
                                    m.Standard.Type = m.OType.Trim().ToUpper();
                                    string strType = m.OType.Trim().ToUpper();
                                    if (!string.IsNullOrEmpty(strType)) {
                                        string keyName = "StdType";
                                        if (keyName != string.Empty) {
                                            string keyValue = m.Standard.Type;
                                            AddParam(keyName, keyValue);
                                        }
                                    }
                                    else {
                                        TempData["Error"] = "Please Enter Type.";
                                    }
                                }

                                if (inputFile != null && inputFile.ContentLength > 0) {
                                    if (inputFile.ContentType == "application/pdf") {
                                        Guid FileName = Guid.NewGuid();
                                        m.Standard.FilePath = "/Uploads/Standards/" + FileName + ".pdf";
                                        string tPath = Path.Combine(Server.MapPath("~/Uploads/Standards/"), FileName + ".pdf");
                                        inputFile.SaveAs(tPath);
                                    }
                                    else {
                                        TempData["Error"] = "Only PDF Files.";
                                    }
                                }
                                else if (!m.file.Equals("")) {
                                    m.Standard.FilePath = m.file;
                                }
                                else {
                                    TempData["Error"] = "Please Select file";
                                }

                                m.Standard.CreatedBy = Request.Cookies["INDMS"]["UserID"];
                                m.Standard.CreatedDate = null;

                                try {
                                    db.Entry(m.Standard).State = EntityState.Modified;
                                    db.SaveChanges();
                                    ModelState.Clear();

                                    TempData["RowId"] = m.Standard.Id;
                                    TempData["MSG"] = "Save Successfully";

                                    return RedirectToAction("Standards");
                                }
                                catch (RetryLimitExceededException /* dex */) {
                                    TempData["Error"] = "Unable to save changes. Try again, and if the problem persists, see your system administrator.";
                                }
                                catch (Exception ex) {
                                    TempData["Error"] = ex.Message;
                                }
                            }
                            else {
                                TempData["Error"] = "Please Select Type.";
                            }
                        }
                        else {
                            TempData["Error"] = "Please Select Subject.";
                        }
                    }
                    else {
                        TempData["Error"] = "Please Enter Revision.";
                    }
                }
                else {
                    TempData["Error"] = "Please Enter Year";
                }
            }
            else {
                TempData["Error"] = "Please Enter Standard No.";
            }

            StandardViewModel mv = new StandardViewModel {
                Standard = m.Standard,
                OSubject = m.OSubject,
                OType = m.OType,
                file = m.file
            };

            return View(mv);
        }
        public ActionResult Standards() {
            StandardViewModel pl = new StandardViewModel {
                Standards = db.Standards.OrderByDescending(x => x.Id)
            };

            return View(pl);
        }