public ActionResult SaveControl(int riskId, string controlName)
        {
            RCMDetailRiskControl newControl = new RCMDetailRiskControl();

            newControl.RCMDetailRiskID = riskId;
            newControl.ControlName     = controlName;
            newControl.ReviewMasterID  = 0;
            newControl.DueDate         = DateTime.Now;
            newControl.CloseDate       = DateTime.Now;
            newControl.Status          = "Pending";
            db.RCMDetailRiskControls.Add(newControl);
            db.SaveChanges();
            string username         = User.Identity.Name;
            int    riskid           = db.RCMDetailRisks.Where(p => p.RCMDetailRiskID.Equals(riskId)).Select(p => p.RCMDetailRiskID).FirstOrDefault();
            int    wallid           = db.RiskControlMatrixs.Where(p => p.RiskControlMatrixID.Equals(riskid)).Select(p => p.WalktroughID).FirstOrDefault();
            RCMDetailRiskControl ri = new RCMDetailRiskControl();

            auditTransact.CreateAuditTrail("Create", wallid, "RCMDetailRiskControl", ri, newControl, username);
            ReviewRelationMaster rrm = new ReviewRelationMaster();
            string page = "control";

            rrm.Description = page + newControl.RCMDetailRiskControlID;
            db.ReviewRelationMasters.Add(rrm);
            db.SaveChanges();
            var        riskControl           = db.RCMDetailRiskControls.Where(p => p.RCMDetailRiskID == riskId).Select(p => new { controlId = p.RCMDetailRiskControlID, controlName = p.ControlName }).ToList();;
            SelectList riskControlSelectList = new SelectList(riskControl, "controlId", "ControlName", 0);

            return(Json(riskControlSelectList));
        }
        public ActionResult CreateAuditUniverse(Activity org, [Bind(Include = "ActivityID,ActivityParentID,Name,Description,Tahun,DepartementID,Status,Status_Active")] Activity activity, string submit)
        {
            if (ModelState.IsValid)
            {
                string username = User.Identity.Name;
                string user     = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    activity.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    activity.Status = HelperController.GetStatusSendback(db, "Audit Universe", activity.Status);
                }
                else if (submit == "Approve")
                {
                    activity.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    activity.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    activity.Status = "Pending for Approve by" + user;
                    string          baseUrl    = Request.Url.GetLeftPart(UriPartial.Authority);
                    List <string>   CIAUserIds = Request.GetOwinContext().GetUserManager <ApplicationRoleManager>().Roles.Where(p => p.Name.Equals(user.Trim())).FirstOrDefault().Users.Select(p => p.UserId).ToList();
                    List <Employee> CIAEmpList = new List <Employee>();
                    if (CIAUserIds.Count() > 0)
                    {
                        var CIAUsers = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(p => (CIAUserIds.Contains(p.Id))).ToList();
                        foreach (var CIAUser in CIAUsers)
                        {
                            Employee emp = db.Employees.Where(p => p.Email.Equals(CIAUser.Email)).FirstOrDefault();

                            string emailContent = "Dear {0}, <BR/><BR/>Audit Universe : {1} need your approval. Please click on this <a href=\"{2}\" title=\"Audit Universe\">link</a> to show the Audit Universe.<BR/><BR/><BR/> Regards,<BR/><BR/> ePatria Team";
                            string url          = baseUrl + "/AuditUniverses/Details?ActivityID=" + org.ActivityID;
                            emailTransact.SentEmailApproval(emp.Email, emp.Name, org.Name, emailContent, url);
                        }
                    }
                }
                db.Activities.Add(activity);
                db.SaveChanges();
                Activity ac = new Activity();
                auditTransact.CreateAuditTrail("Create", activity.ActivityID, "AuditUniverse", ac, activity, username);
                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "au";
                rrm.Description = page + activity.ActivityID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();
                TempData["message"] = "Audit Universe successfully created!";
                return(RedirectToAction("Index"));
            }

            return(View(activity));
        }
        public async Task <ActionResult> CreateRCM(IEnumerable <HttpPostedFileBase> files, [Bind(Include = "RiskControlMatrixID,BusinessProcesID,SubBusinessProcess,Objectives,WalktroughID")] RiskControlMatrix rcm, string bpms, string submit)
        {
            if (ModelState.IsValid)
            {
                var bpm = db.BPMs.Where(p => p.Name.Equals(bpms)).FirstOrDefault();
                if (bpm != null && bpm.Status == "Approve")
                {
                    int bpmid = bpm.BPMID;
                    rcm.BusinessProcesID = bpmid;
                    string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                    if (submit == "Save")
                    {
                        rcm.Status = "Draft";
                    }
                    else if (submit == "Send Back")
                    {
                        rcm.Status = "Draft";
                    }
                    else if (submit == "Approve")
                    {
                        rcm.Status = "Approve";
                    }
                    else if (submit == "Submit For Review By" + user)
                    {
                        rcm.Status = "Pending for Review by" + user;
                    }
                    else if (submit == "Submit For Approve By" + user)
                    {
                        bpm.Status = "Pending for Approve by" + user;
                    }
                    db.RiskControlMatrixs.Add(rcm);
                    await db.SaveChangesAsync();

                    await db.SaveChangesAsync();

                    ReviewRelationMaster rrm = new ReviewRelationMaster();
                    string page = "rcm";
                    rrm.Description = page + rcm.RiskControlMatrixID;
                    db.ReviewRelationMasters.Add(rrm);
                    db.SaveChanges();
                    string username = User.Identity.Name;
                    int    wallid   = Convert.ToInt32(rcm.WalktroughID);

                    RiskControlMatrix rc = new RiskControlMatrix();
                    auditTransact.CreateAuditTrail("Create", wallid, "RiskControlMatrix", rc, rcm, username);
                    //return RedirectToAction("Create");
                }
            }
            return(RedirectToAction("Create", new { id = rcm.WalktroughID }));
        }
        public async Task <ActionResult> CreateBPM(IEnumerable <HttpPostedFileBase> files, [Bind(Include = "BPMID,WalktroughID,Name")] BPM bpm, string submit, int WalktroughID)
        {
            if (ModelState.IsValid)
            {
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save" || submit == "Send Back")
                {
                    bpm.Status = "Draft";
                }
                else if (submit == "Approve")
                {
                    bpm.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    bpm.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    bpm.Status = "Pending for Approve by" + user;
                }

                db.BPMs.Add(bpm);
                await db.SaveChangesAsync();

                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "bpm";
                rrm.Description = page + bpm.BPMID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();
                string username = User.Identity.Name;
                int    wallid   = Convert.ToInt32(bpm.WalktroughID);
                BPM    bp       = new BPM();
                auditTransact.CreateAuditTrail("Create", wallid, "BPM", bp, bpm, username);
                TempData["message"] = "BPM successfully created!";
                return(RedirectToAction("CreateBusiness", new { id = bpm.BPMID, walkid = WalktroughID }));
                //return RedirectToAction("Create");
            }
            return(View(bpm));
        }
Beispiel #5
0
        public ActionResult Create(string submit, [Bind(Include = "AnnualPlanningID,Date_Start,Date_End,Status,Approval_Status,Tahun,ActivityID,PICID,SupervisorID,TeamLeaderID,MemberID")] AnnualPlanning annualPlanning, string[] member, string supervisor, string pic, string leader, EngagementActivity engagementActivity)
        {
            if (ModelState.IsValid)
            {
                HttpServerUtilityBase server = Server;
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    annualPlanning.Approval_Status = "Draft";
                }
                else if (submit == "Approve")
                {
                    annualPlanning.Approval_Status = "Approve";
                }
                else if (submit == "Send Back")
                {
                    annualPlanning.Approval_Status = HelperController.GetStatusSendback(db, "Annual Planning", annualPlanning.Approval_Status);
                }
                else if (submit == "Submit For Review By" + user)
                {
                    annualPlanning.Approval_Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    annualPlanning.Approval_Status = "Pending for Approve by" + user;
                    string          activname = db.Activities.Where(p => p.ActivityID.Equals(annualPlanning.ActivityID)).Select(p => p.Name).FirstOrDefault();
                    string          baseUrl   = Request.Url.GetLeftPart(UriPartial.Authority);
                    List <string>   UserIds   = Request.GetOwinContext().GetUserManager <ApplicationRoleManager>().Roles.Where(p => p.Name.Equals(user.Trim())).FirstOrDefault().Users.Select(p => p.UserId).ToList();
                    List <Employee> EmpList   = new List <Employee>();
                    if (UserIds.Count() > 0)
                    {
                        var users = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(p => (UserIds.Contains(p.Id))).ToList();
                        foreach (var userr in users)
                        {
                            Employee emp = db.Employees.Where(p => p.Email.Equals(userr.Email)).FirstOrDefault();
                            if (emp != null)
                            {
                                string emailContent = "Dear {0}, <BR/><BR/>There is a Annual Planning that need your approval. Please click on this <a href=\"{2}\" title=\"Annual Planning\">link</a> to show the Annual Planning.<BR/><BR/><BR/> Regards,<BR/><BR/> ePatria Team";
                                string url          = baseUrl + "/AnnualPlannings/Details/" + annualPlanning.AnnualPlanningID;
                                emailTransact.SentEmailApproval(emp.Email, emp.Name, activname, emailContent, url);
                            }
                        }
                    }
                }

                db.AnnualPlannings.Add(annualPlanning);
                db.SaveChanges();
                string         username = User.Identity.Name;
                AnnualPlanning an       = new AnnualPlanning();
                auditTransact.CreateAuditTrail("Create", annualPlanning.AnnualPlanningID, "AnnualPlanning", an, annualPlanning, username);

                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "apl";
                rrm.Description = page + annualPlanning.AnnualPlanningID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();

                TempData["message"] = "Annual Planning successfully created!";
                return(RedirectToAction("Index"));
            }
            ActivityServices activity = new ActivityServices();
            var activities            = activity.GetActivity().Where(p => p.Status == "Approve");
            IEnumerable <SelectListItem> activityid = activities
                                                      .Select(d => new SelectListItem
            {
                Value = d.ActivityID.ToString(),
                Text  = d.Name
            });

            ViewBag.ActivityID = activityid;
            ViewBag.membereng  = new MultiSelectList(db.Employees, "EmployeeID", "Name");
            ViewBag.membereng1 = new MultiSelectList(db.Employees, "EmployeeID", "Name");
            return(View(annualPlanning));
        }
        public ActionResult Create(string nomerapm, string membernull, string enggname, EngagementActivity engga, AuditPlanningMemorandum audit, [Bind(Include = "AuditPlanningMemorandumID,NomerAPM,PreliminaryID,Date_Start,Date_End,Status,ActivityID,TujuanAudit,RuangLingkupAudit,MetodologiAudit,DataDanDokumen,AttachmentMasterID,EntryMeetingDateStart,EntryMeetingDateEnd,WalktroughDateStart,WalktroughDateEnd,FieldWorkDateStart,FieldWorkDateEnd,ExitMeetingDateStart,ExitMeetingDateEnd,LHADateStart,LHADateEnd,PICID,SupervisorID,TeamLeaderID,MemberID,ReviewMasterID,Kesimpulan,ActualEngagement")] AuditPlanningMemorandum auditPlanningMemorandum, IEnumerable <HttpPostedFileBase> files, string submit, string[] members, string supervisor, string pic, string leader, string nomer, string activid)
        {
            if (ModelState.IsValid)
            {
                HttpServerUtilityBase server = Server;
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    auditPlanningMemorandum.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    HelperController.GetStatusSendback(db, "Audit Planning Memorandum", auditPlanningMemorandum.Status);
                }
                else if (submit == "Approve")
                {
                    auditPlanningMemorandum.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    auditPlanningMemorandum.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    auditPlanningMemorandum.Status = "Pending for Approve by" + user;
                    string userToSentEmail = String.Empty;
                    if (user.Trim() == "CIA")
                    {
                        userToSentEmail = auditPlanningMemorandum.PICID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailAPM(userToSentEmail, auditPlanningMemorandum);
                        }
                        else
                        {
                            sentEmailAPM(auditPlanningMemorandum, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Pengawas")
                    {
                        userToSentEmail = auditPlanningMemorandum.SupervisorID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailAPM(userToSentEmail, auditPlanningMemorandum);
                        }
                        else
                        {
                            sentEmailAPM(auditPlanningMemorandum, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Ketua Tim")
                    {
                        userToSentEmail = auditPlanningMemorandum.TeamLeaderID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailAPM(userToSentEmail, auditPlanningMemorandum);
                        }
                        else
                        {
                            sentEmailAPM(auditPlanningMemorandum, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Member")
                    {
                        userToSentEmail = auditPlanningMemorandum.MemberID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailAPM(userToSentEmail, auditPlanningMemorandum);
                        }
                        else
                        {
                            sentEmailAPM(auditPlanningMemorandum, user.Trim());
                        }
                    }
                }

                foreach (var mem in members)
                {
                    auditPlanningMemorandum.MemberID += mem + ";";
                }

                IQueryable <Preliminary> prel = db.Preliminaries.Where(p => p.NomorPreliminarySurvey.Equals(nomer));
                int preID = 0;
                if (prel.Count() > 0 || prel != null)
                {
                    preID = prel.Select(p => p.PreliminaryID).FirstOrDefault();
                }
                auditPlanningMemorandum.PreliminaryID = preID;
                auditPlanningMemorandum.SupervisorID  = supervisor;
                auditPlanningMemorandum.TeamLeaderID  = leader;
                auditPlanningMemorandum.PICID         = pic;

                IQueryable <Activity> act = db.Activities.Where(p => p.Name.Equals(activid));
                int actid = 0;
                if (act.Count() > 0 || act != null)
                {
                    actid = act.Select(p => p.ActivityID).FirstOrDefault();
                }
                auditPlanningMemorandum.ActivityID = actid;
                auditPlanningMemorandum.NomerAPM   = nomerapm;
                db.AuditPlanningMemorandums.Add(auditPlanningMemorandum);
                db.SaveChanges();
                int i = 0;
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        i = i + 1;
                        bool addFile = filesTransact.addFile(auditPlanningMemorandum.NomerAPM.Replace("/", ""), i, file, server);
                    }
                }
                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "apm";
                rrm.Description = page + auditPlanningMemorandum.AuditPlanningMemorandumID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();
                string username            = User.Identity.Name;
                AuditPlanningMemorandum au = new AuditPlanningMemorandum();
                auditTransact.CreateAuditTrail("Create", auditPlanningMemorandum.AuditPlanningMemorandumID, "AuditPlanningMemorandum", au, auditPlanningMemorandum, username);

                TempData["message"] = "Audit Planning Memorandum successfully created!";
                return(RedirectToAction("Index"));
            }
            return(View(auditPlanningMemorandum));
        }
        public ActionResult Create([Bind(Include = "ConsultingSuratPerintahID,NomorSP,ConsultingRequestID,EngagementName,EngagementID,StartDate,EndDate,PicID,SupervisorID,TeamLeaderID,Menimbang,Penutup,MemberID,Remarks")] ConsultingLetterOfCommand consultingletterofcommand,
                                   EngagementActivity engagementActivity, string ActivityName, string submit,
                                   string[] member, string ConsultingRequest, ConsultingLetterOfCommandDetailDasar Ldasar,
                                   ConsultingLetterOfCommandDetailTembusan Ltembusan, ConsultingLetterOfCommandDetailUntuk Luntuk,
                                   string[] dasar, string[] tembusan, string[] untuk)
        {
            if (ModelState.IsValid)
            {
                string username = User.Identity.Name;
                IQueryable <ConsultingRequest> cr = context.ConsultingRequests.Where(p => p.NoRequest.Equals(ConsultingRequest));
                int ConsulId = 0;
                if (cr.Count() > 0 || cr != null)
                {
                    ConsulId = cr.Select(p => p.ConsultingRequestID).FirstOrDefault();
                }
                consultingletterofcommand.ConsultingRequestID = ConsulId;
                foreach (var mb in member)
                {
                    consultingletterofcommand.MemberID += mb + ";";
                }
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    consultingletterofcommand.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    consultingletterofcommand.Status = HelperController.GetStatusSendback(context, "Consulting Surat Perintah", consultingletterofcommand.Status);
                }
                else if (submit == "Approve")
                {
                    consultingletterofcommand.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    consultingletterofcommand.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    consultingletterofcommand.Status = "Pending for Approve by" + user;
                }

                context.ConsultingLetterOfCommands.Add(consultingletterofcommand);

                //Engagement Activity

                //IQueryable<Activity> act = context.Activities.Where(p => p.Name.Equals(ActivityName));
                //int ActivityID = 0;
                //if (act.Count() > 0 || act != null)
                //    ActivityID = act.Select(p => p.ActivityID).FirstOrDefault();
                engagementActivity.ActivityStr  = ActivityName;
                engagementActivity.Name         = consultingletterofcommand.EngagementName;
                engagementActivity.PICID        = consultingletterofcommand.PicID;
                engagementActivity.TeamLeaderID = consultingletterofcommand.TeamLeaderID;
                engagementActivity.SupervisorID = consultingletterofcommand.SupervisorID;
                engagementActivity.MemberID     = consultingletterofcommand.MemberID;
                context.EngagementActivities.Add(engagementActivity);

                //Letter of Command Dasar
                Ldasar.ConsultingSuratPerintahID = consultingletterofcommand.ConsultingSuratPerintahID;
                Ldasar.Dasar = null;
                foreach (var ds in dasar)
                {
                    Ldasar.Dasar += ds + ";";
                }
                context.ConsultingLetterOfCommandDetailDasars.Add(Ldasar);

                //Letter of Command Untuk
                Luntuk.ConsultingSuratPerintahID = consultingletterofcommand.ConsultingSuratPerintahID;
                Luntuk.Untuk = null;
                foreach (var utk in untuk)
                {
                    Luntuk.Untuk += utk + ";";
                }
                context.ConsultingLetterOfCommandDetailUntuks.Add(Luntuk);

                //Letter of Command Tembusan
                Ltembusan.ConsultingSuratPerintahID = consultingletterofcommand.ConsultingSuratPerintahID;
                Ltembusan.Tembusan = null;
                foreach (var tmb in tembusan)
                {
                    Ltembusan.Tembusan += tmb + ";";
                }
                context.ConsultingLetterOfCommandDetailTembusans.Add(Ltembusan);

                context.SaveChanges();

                //assign engagementID in consulting SP
                consultingletterofcommand.EngagementID         = engagementActivity.EngagementID;
                context.Entry(consultingletterofcommand).State = EntityState.Modified;

                //Review Relation Master
                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "conleterdetail";
                rrm.Description = page + consultingletterofcommand.ConsultingSuratPerintahID;
                context.ReviewRelationMasters.Add(rrm);
                context.SaveChanges();
                ConsultingLetterOfCommand               conletcom      = new ConsultingLetterOfCommand();
                ConsultingLetterOfCommandDetailDasar    conletdasar    = new ConsultingLetterOfCommandDetailDasar();
                ConsultingLetterOfCommandDetailUntuk    conletuntuk    = new ConsultingLetterOfCommandDetailUntuk();
                ConsultingLetterOfCommandDetailTembusan conlettembusan = new ConsultingLetterOfCommandDetailTembusan();
                ConsultingLetterOfCommand               conletnew      = context.ConsultingLetterOfCommands.Find(consultingletterofcommand.ConsultingSuratPerintahID);
                auditTransact.CreateAuditTrail("Create", consultingletterofcommand.ConsultingSuratPerintahID, "Consulting Letter Of Command", conletcom, conletnew, username);
                auditTransact.CreateAuditTrail("Create", Ldasar.ConsultingLetterOfCommandDetailDasarID, "Consulting Letter Of Command Dasar", conletdasar, Ldasar, username);
                auditTransact.CreateAuditTrail("Create", Luntuk.ConsultingLetterOfCommandDetailUntukID, "Consulting Letter Of Command Untuk", conletuntuk, Luntuk, username);
                auditTransact.CreateAuditTrail("Create", Ltembusan.ConsultingLetterOfCommandDetailTembusanID, "Consulting Letter Of Command Tembusan", conlettembusan, Ltembusan, username);
                TempData["message"] = "Consulting Letter Of Command successfully created!";
                return(RedirectToAction("Index"));
            }

            return(View(consultingletterofcommand));
        }
        public ActionResult Create(string submit, string requester, [Bind(Include = "ConsultingRequestID,NoRequest,NoSurat,RequesterID,Date_Start,EvaluationResult,Status,ActivityStr")] ConsultingRequest consultingRequest, IEnumerable <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                string username           = User.Identity.Name;
                IQueryable <Employee> emp = db.Employees.Where(p => p.Name.Equals(requester));
                int empId = 0;
                if (emp.Count() > 0 || emp != null)
                {
                    empId = emp.Select(p => p.EmployeeID).FirstOrDefault();
                }

                consultingRequest.RequesterID = empId;

                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    consultingRequest.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    consultingRequest.Status = HelperController.GetStatusSendback(db, "Consulting Request", consultingRequest.Status);
                }
                else if (submit == "Submit For Review By" + user)
                {
                    consultingRequest.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    consultingRequest.Status = "Pending for Approve by" + user;
                    string          baseUrl    = Request.Url.GetLeftPart(UriPartial.Authority);
                    List <string>   CIAUserIds = Request.GetOwinContext().GetUserManager <ApplicationRoleManager>().Roles.Where(p => p.Name.Equals(user.Trim())).FirstOrDefault().Users.Select(p => p.UserId).ToList();
                    List <Employee> CIAEmpList = new List <Employee>();
                    if (CIAUserIds.Count() > 0)
                    {
                        var CIAUsers = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(p => (CIAUserIds.Contains(p.Id))).ToList();
                        foreach (var CIAUser in CIAUsers)
                        {
                            Employee empl = db.Employees.Where(p => p.Email.Equals(CIAUser.Email)).FirstOrDefault();

                            string emailContent = "Dear {0}, <BR/><BR/>Consulting Request : {1} need your approval. Please click on this <a href=\"{2}\" title=\"Consulting Request\">link</a> to show the Consulting Request.<BR/><BR/><BR/> Regards,<BR/><BR/> ePatria Team";
                            string urlRequest   = baseUrl + "/ConsultingRequests/Details/" + consultingRequest.ConsultingRequestID;
                            emailTransact.SentEmailApproval(empl.Email, empl.Name, consultingRequest.NoRequest, emailContent, urlRequest);
                        }
                    }
                }

                HttpServerUtilityBase server = Server;
                //var createFile = UploadFile(1234);
                int i = 0;
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        i = i + 1;
                        bool addFile = filesTransact.addFile(consultingRequest.NoRequest.Replace("/", ""), i, file, server);
                    }
                }

                db.ConsultingRequests.Add(consultingRequest);
                db.SaveChanges();
                ConsultingRequest conreq = new ConsultingRequest();
                auditTransact.CreateAuditTrail("Create", consultingRequest.ConsultingRequestID, "Consulting Request", conreq, consultingRequest, username);
                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "draft";
                rrm.Description = page + consultingRequest.ConsultingRequestID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();
                TempData["message"] = "Request successfully created!";
                return(RedirectToAction("Index"));
            }

            //ViewBag.ActivityID = new SelectList(db.Activities, "ActivityID", "Name", consultingRequest.ActivityID);
            return(View(consultingRequest));
        }
        public ActionResult Create(string noprelim, int?ActivityID, string EngagementNameNull, string EngagementName, int?UnActivityID, int?engid, [Bind(Include = "PreliminaryID,Type,Status,NomorPreliminarySurvey,Date_Start,Date_End,EmployeeID,EngagementID,PICID,SupervisorID,TeamLeaderID,MemberID")] Preliminary preliminary, IEnumerable <HttpPostedFileBase> files, string submit, string[] member,
                                   string pic, string supervisor, string leader, string[] members)
        {
            if (ModelState.IsValid)
            {
                if (member != null)
                {
                    foreach (var mem in member)
                    {
                        preliminary.EmployeeID += mem + ";";
                    }
                }

                preliminary.PICID        = pic;
                preliminary.SupervisorID = supervisor;
                preliminary.TeamLeaderID = leader;
                if (members != null)
                {
                    foreach (var mem in members)
                    {
                        preliminary.MemberID += mem + ";";
                    }
                }

                HttpServerUtilityBase server = Server;
                int a = 0;
                if (engid == 0 && a < ActivityID)
                {
                    EngagementActivity engagement = new EngagementActivity();

                    engagement.ActivityID = ActivityID.Value;
                    engagement.Name       = EngagementNameNull;
                    engagement.Date_Start = null;
                    engagement.Date_End   = null;
                    db.EngagementActivities.Add(engagement);
                    db.SaveChanges();

                    preliminary.ActivityID             = ActivityID.Value;
                    preliminary.EngagementID           = engagement.EngagementID;
                    preliminary.NomorPreliminarySurvey = noprelim;
                    int i = 0;
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            i = i + 1;
                            var  pre     = preliminary.NomorPreliminarySurvey.Split('/')[0];
                            var  no      = preliminary.NomorPreliminarySurvey.Split('/')[1];
                            bool addFile = filesTransact.addFile(pre + no, i, file, server);
                        }
                    }

                    string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                    if (submit == "Save")
                    {
                        preliminary.Status = "Draft";
                    }
                    else if (submit == "Send Back")
                    {
                        preliminary.Status = HelperController.GetStatusSendback(db, "Preliminary Survey", preliminary.Status);
                    }
                    else if (submit == "Approve")
                    {
                        preliminary.Status = "Approve";
                    }
                    else if (submit == "Submit For Review By" + user)
                    {
                        preliminary.Status = "Pending for Review by" + user;
                    }
                    else if (submit == "Submit For Approve By" + user)
                    {
                        preliminary.Status = "Pending for Approve by" + user;
                        string userToSentEmail = String.Empty;
                        if (user.Trim() == "CIA")
                        {
                            userToSentEmail = preliminary.PICID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Pengawas")
                        {
                            userToSentEmail = preliminary.SupervisorID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Ketua Tim")
                        {
                            userToSentEmail = preliminary.TeamLeaderID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Member")
                        {
                            userToSentEmail = preliminary.MemberID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                    }
                    db.Preliminaries.Add(preliminary);
                    db.SaveChanges();
                    string      username = User.Identity.Name;
                    Preliminary pr       = new Preliminary();
                    auditTransact.CreateAuditTrail("Create", preliminary.PreliminaryID, "Preliminary", pr, preliminary, username);

                    ReviewRelationMaster rrm = new ReviewRelationMaster();
                    string page = "prelim";
                    rrm.Description = page + preliminary.PreliminaryID;
                    db.ReviewRelationMasters.Add(rrm);
                    db.SaveChanges();
                }
                else
                if (preliminary.Type == "UnPlanned")
                {
                    EngagementActivity engagement = new EngagementActivity();


                    engagement.ActivityID = UnActivityID.Value;
                    engagement.Name       = EngagementName;
                    engagement.Date_Start = null;
                    engagement.Date_End   = null;
                    db.EngagementActivities.Add(engagement);
                    db.SaveChanges();

                    preliminary.ActivityID             = UnActivityID.Value;
                    preliminary.EngagementID           = engagement.EngagementID;
                    preliminary.NomorPreliminarySurvey = noprelim;
                    int i = 0;
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            i = i + 1;
                            var  pre     = preliminary.NomorPreliminarySurvey.Split('/')[0];
                            var  no      = preliminary.NomorPreliminarySurvey.Split('/')[1];
                            bool addFile = filesTransact.addFile(pre + no, i, file, server);
                        }
                    }

                    string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                    if (submit == "Save")
                    {
                        preliminary.Status = "Draft";
                    }
                    else if (submit == "Send Back")
                    {
                        preliminary.Status = HelperController.GetStatusSendback(db, "Preliminary Survey", preliminary.Status);
                    }
                    else if (submit == "Approve")
                    {
                        preliminary.Status = "Approve";
                    }
                    else if (submit == "Submit For Review By" + user)
                    {
                        preliminary.Status = "Pending for Review by" + user;
                    }
                    else if (submit == "Submit For Approve By" + user)
                    {
                        preliminary.Status = "Pending for Approve by" + user;
                        string userToSentEmail = String.Empty;
                        if (user.Trim() == "CIA")
                        {
                            userToSentEmail = preliminary.PICID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Pengawas")
                        {
                            userToSentEmail = preliminary.SupervisorID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Ketua Tim")
                        {
                            userToSentEmail = preliminary.TeamLeaderID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Member")
                        {
                            userToSentEmail = preliminary.MemberID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                    }
                    db.Preliminaries.Add(preliminary);
                    db.SaveChanges();
                    string      username = User.Identity.Name;
                    Preliminary pr       = new Preliminary();
                    auditTransact.CreateAuditTrail("Create", preliminary.PreliminaryID, "Preliminary", pr, preliminary, username);
                    ReviewRelationMaster rrm = new ReviewRelationMaster();
                    string page = "prelim";
                    rrm.Description = page + preliminary.PreliminaryID;
                    db.ReviewRelationMasters.Add(rrm);

                    db.SaveChanges();
                }
                else //Type == "Planned"
                {
                    EngagementActivity engagement = new EngagementActivity();

                    preliminary.ActivityID             = ActivityID.Value;
                    preliminary.EngagementID           = engid;
                    preliminary.NomorPreliminarySurvey = noprelim;
                    int i = 0;
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            i = i + 1;
                            var  pre     = preliminary.NomorPreliminarySurvey.Split('/')[0];
                            var  no      = preliminary.NomorPreliminarySurvey.Split('/')[1];
                            bool addFile = filesTransact.addFile(pre + no, i, file, server);
                        }
                    }

                    string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                    if (submit == "Save")
                    {
                        preliminary.Status = "Draft";
                    }
                    else if (submit == "Send Back")
                    {
                        preliminary.Status = HelperController.GetStatusSendback(db, "Preliminary Survey", preliminary.Status);
                    }
                    else if (submit == "Approve")
                    {
                        preliminary.Status = "Approve";
                    }
                    else if (submit == "Submit For Review By" + user)
                    {
                        preliminary.Status = "Pending for Review by" + user;
                    }
                    else if (submit == "Submit For Approve By" + user)
                    {
                        preliminary.Status = "Pending for Approve by" + user;
                        string userToSentEmail = String.Empty;
                        if (user.Trim() == "CIA")
                        {
                            userToSentEmail = preliminary.PICID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Pengawas")
                        {
                            userToSentEmail = preliminary.SupervisorID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Ketua Tim")
                        {
                            userToSentEmail = preliminary.TeamLeaderID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                        else if (user.Trim() == "Member")
                        {
                            userToSentEmail = preliminary.MemberID;
                            if (userToSentEmail != null)
                            {
                                sentSingleEmailPrelim(userToSentEmail, preliminary);
                            }
                            else
                            {
                                sentEmailPrelim(preliminary, user.Trim());
                            }
                        }
                    }
                    db.Preliminaries.Add(preliminary);
                    db.SaveChanges();
                    string      username = User.Identity.Name;
                    Preliminary pr       = new Preliminary();
                    auditTransact.CreateAuditTrail("Create", preliminary.PreliminaryID, "Preliminary", pr, preliminary, username);
                    ReviewRelationMaster rrm = new ReviewRelationMaster();
                    string page = "prelim";
                    rrm.Description = page + preliminary.PreliminaryID;
                    db.ReviewRelationMasters.Add(rrm);
                    db.SaveChanges();
                }
                TempData["message"] = "Preliminary successfully created!";
                return(RedirectToAction("Index"));
            }



            return(View(preliminary));
        }
Beispiel #10
0
        public async Task <ActionResult> Create(string submit, [Bind(Include = "QuestionerID,Name,Type,Value,Status")] Questioner questioner, string Textarea, string Textbox, string Rating, string from, string to)
        {
            if (ModelState.IsValid)
            {
                if (questioner.Type == "TextBox")
                {
                    questioner.Value = Textbox;
                }
                else if (questioner.Type == "TextArea")
                {
                    questioner.Value = Textarea;
                }
                else
                {
                    questioner.Value = from + ";" + to;
                }
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save" || submit == "Send Back")
                {
                    questioner.Status = "Draft";
                }
                else if (submit == "Approve")
                {
                    questioner.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    questioner.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    questioner.Status = "Pending for Approve by" + user;
                    string          baseUrl    = Request.Url.GetLeftPart(UriPartial.Authority);
                    List <string>   CIAUserIds = Request.GetOwinContext().GetUserManager <ApplicationRoleManager>().Roles.Where(p => p.Name.Equals(user.Trim())).FirstOrDefault().Users.Select(p => p.UserId).ToList();
                    List <Employee> CIAEmpList = new List <Employee>();
                    if (CIAUserIds.Count() > 0)
                    {
                        var CIAUsers = Request.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.Where(p => (CIAUserIds.Contains(p.Id))).ToList();
                        foreach (var CIAUser in CIAUsers)
                        {
                            Employee emp = db.Employees.Where(p => p.Email.Equals(CIAUser.Email)).FirstOrDefault();

                            string emailContent = "Dear {0}, <BR/><BR/>Questioner : {1} need your approval. Please click on this <a href=\"{2}\" title=\"Questioner\">link</a> to show the Questioner.<BR/><BR/><BR/> Regards,<BR/><BR/> ePatria Team";
                            string url          = baseUrl + "/Questioners/Details/" + questioner.QuestionerID;
                            //emailTransact.SentEmailApproval(emp.Email, emp.Name, questioner.Name, emailContent, url);
                        }
                    }
                }
                db.Questioners.Add(questioner);
                await db.SaveChangesAsync();

                string     username = User.Identity.Name;
                Questioner qus      = new Questioner();
                auditTransact.CreateAuditTrail("Create", questioner.QuestionerID, "Questioner", qus, questioner, username);

                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "questioner";
                rrm.Description = page + questioner.QuestionerID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();

                TempData["message"] = "Questioner successfully created!";
                return(RedirectToAction("Index"));
            }

            return(View(questioner));
        }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "ExitMeetingID,ActivityID,EngagementID,Date_Start,Date_End,Status,OrganizationID,LetterOfCommandID,Reviewer1,Reviewer2")] ExitMeeting exitMeeting, string activname, string enggname, string submit, string organame, string nomersp, string period1, string period2)
        {
            if (ModelState.IsValid)
            {
                string username           = User.Identity.Name;
                IQueryable <Activity> act = db.Activities.Where(p => p.Name.Equals(activname));
                int actID = 0;
                if (act.Count() > 0 || act != null)
                {
                    actID = act.Select(p => p.ActivityID).FirstOrDefault();
                }
                exitMeeting.ActivityID = actID;

                IQueryable <EngagementActivity> eng = db.EngagementActivities.Where(p => p.Name.Equals(enggname));
                int engID = 0;
                if (eng.Count() > 0 || eng != null)
                {
                    engID = eng.Select(p => p.EngagementID).FirstOrDefault();
                }
                exitMeeting.EngagementID = engID;
                exitMeeting.Date_Start   = Convert.ToDateTime(period1);
                exitMeeting.Date_End     = Convert.ToDateTime(period2);

                IQueryable <Organization> org = db.Organizations.Where(p => p.Name.Equals(organame));
                int orgID = 0;
                if (act.Count() > 0 || act != null)
                {
                    orgID = org.Select(p => p.OrganizationID).FirstOrDefault();
                }
                exitMeeting.OrganizationID = orgID;

                IQueryable <LetterOfCommand> letter = db.LetterOfCommands.Where(p => p.NomorSP.Equals(nomersp));
                int letterID = 0;
                if (letter.Count() > 0 || letter != null)
                {
                    letterID = letter.Select(p => p.LetterOfCommandID).FirstOrDefault();
                }
                exitMeeting.LetterOfCommandID = letterID;
                LetterOfCommand sp   = db.LetterOfCommands.Find(exitMeeting.LetterOfCommandID);
                string          user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    exitMeeting.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    exitMeeting.Status = HelperController.GetStatusSendback(db, "Exit Meeting", exitMeeting.Status);
                }
                else if (submit == "Approve")
                {
                    exitMeeting.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    exitMeeting.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    exitMeeting.Status = "Pending for Approve by" + user;
                    string userToSentEmail = String.Empty;
                    if (user.Trim() == "CIA")
                    {
                        userToSentEmail = sp.PICID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailEM(userToSentEmail, exitMeeting);
                        }
                        else
                        {
                            sentEmailEM(exitMeeting, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Pengawas")
                    {
                        userToSentEmail = sp.SupervisorID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailEM(userToSentEmail, exitMeeting);
                        }
                        else
                        {
                            sentEmailEM(exitMeeting, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Ketua Tim")
                    {
                        userToSentEmail = sp.TeamLeaderID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailEM(userToSentEmail, exitMeeting);
                        }
                        else
                        {
                            sentEmailEM(exitMeeting, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Member")
                    {
                        userToSentEmail = sp.MemberID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailEM(userToSentEmail, exitMeeting);
                        }
                        else
                        {
                            sentEmailEM(exitMeeting, user.Trim());
                        }
                    }
                }
                exitMeeting.StatusTanggapan = "On Progress";
                db.ExitMeetings.Add(exitMeeting);
                db.SaveChanges();
                ExitMeeting exitmeet = new ExitMeeting();
                auditTransact.CreateAuditTrail("Create", exitMeeting.ExitMeetingID, "Exit Meeting", exitmeet, exitMeeting, username);

                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "exitmeet";
                rrm.Description = page + exitMeeting.ExitMeetingID;
                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();

                TempData["message"] = "Exit Meeting successfully created!";
                return(RedirectToAction("Index"));
            }

            //LetterOfCommand letter = db.LetterOfCommands.Where(p => p.NomorSP.Equals(nomersp)).FirstOrDefault();
            //var activId = letter.ActivityID;
            //var engId = letter.Preliminary.EngagementID;
            //var orgId = letter.Activity.DepartementID;
            //string activnam = db.Activities.Find(activId).Name;
            //string engname = db.EngagementActivities.Find(engId).Name;
            //string orgname = db.Organizations.Find(orgId).Name;
            //var data =  activnam + "," + engname + "," + orgname;
            return(View(exitMeeting));
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "LetterOfCommandID,NomorSP,Status,Remarks,AssuranceType,Date_Start,Date_End,Menimbang,Penutup,AuditPlanningMemorandumID,ActivityID,PICID,SupervisorID,TeamLeaderID,MemberID")] LetterOfCommand letterOfCommand,
                                   LetterOfCommandDetailDasar letterOfCommandDetailDasar, LetterOfCommandDetailUntuk letterOfCommandDetailUntuk,
                                   LetterOfCommandDetailTembusan letterOfCommandDetailTembusan, string letterno, string membernull,
                                   string activid, string[] members, string pic, string supervisor, string leader, string nomer,
                                   string submit, string[] dasar, string[] untuk, string[] tembusan)
        {
            if (ModelState.IsValid)
            {
                string username = User.Identity.Name;

                HttpServerUtilityBase server = Server;
                string user = submit.Contains("By") ? submit.Split('y')[1] : String.Empty;
                if (submit == "Save")
                {
                    letterOfCommand.Status = "Draft";
                }
                else if (submit == "Send Back")
                {
                    letterOfCommand.Status = HelperController.GetStatusSendback(db, "Surat Perintah", letterOfCommand.Status);
                }
                else if (submit == "Approve")
                {
                    letterOfCommand.Status = "Approve";
                }
                else if (submit == "Submit For Review By" + user)
                {
                    letterOfCommand.Status = "Pending for Review by" + user;
                }
                else if (submit == "Submit For Approve By" + user)
                {
                    letterOfCommand.Status = "Pending for Approve by" + user;
                    string userToSentEmail = String.Empty;
                    if (user.Trim() == "CIA")
                    {
                        userToSentEmail = letterOfCommand.PICID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailSP(userToSentEmail, letterOfCommand);
                        }
                        else
                        {
                            sentEmailSP(letterOfCommand, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Pengawas")
                    {
                        userToSentEmail = letterOfCommand.SupervisorID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailSP(userToSentEmail, letterOfCommand);
                        }
                        else
                        {
                            sentEmailSP(letterOfCommand, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Ketua Tim")
                    {
                        userToSentEmail = letterOfCommand.TeamLeaderID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailSP(userToSentEmail, letterOfCommand);
                        }
                        else
                        {
                            sentEmailSP(letterOfCommand, user.Trim());
                        }
                    }
                    else if (user.Trim() == "Member")
                    {
                        userToSentEmail = letterOfCommand.MemberID;
                        if (userToSentEmail != null)
                        {
                            sentSingleEmailSP(userToSentEmail, letterOfCommand);
                        }
                        else
                        {
                            sentEmailSP(letterOfCommand, user.Trim());
                        }
                    }
                }

                IQueryable <AuditPlanningMemorandum> apm = db.AuditPlanningMemorandums.Where(p => p.NomerAPM.Equals(nomer));
                int apmId = 0;
                if (apm.Count() > 0 || apm != null)
                {
                    apmId = apm.Select(p => p.AuditPlanningMemorandumID).FirstOrDefault();
                    letterOfCommand.AuditPlanningMemorandumID = apmId;
                }
                letterOfCommand.SupervisorID = supervisor;
                letterOfCommand.TeamLeaderID = leader;
                letterOfCommand.PICID        = pic;


                IQueryable <Activity> act = db.Activities.Where(p => p.Name.Equals(activid));
                int activ = 0;
                if (act.Count() > 0 || act != null)
                {
                    activ = act.Select(p => p.ActivityID).FirstOrDefault();
                }
                letterOfCommand.ActivityID = activ;

                string   tahun1    = letterOfCommand.Date_Start.ToShortDateString().Split('/')[2] + ";";
                string   tahun2    = letterOfCommand.Date_End.ToShortDateString().Split('/')[2] + ";";
                Activity actLetter = db.Activities.Find(activ);
                if (actLetter.Tahun != null)
                {
                    if (tahun1 != tahun2)
                    {
                        if (!actLetter.Tahun.Contains(tahun1))
                        {
                            actLetter.Tahun += tahun1;
                        }
                        if (!actLetter.Tahun.Contains(tahun2))
                        {
                            actLetter.Tahun += tahun2;
                        }
                    }
                    else
                    {
                        if (!actLetter.Tahun.Contains(tahun1))
                        {
                            actLetter.Tahun += tahun1;
                        }
                    }
                }
                else
                {
                    if (tahun1 != tahun2)
                    {
                        actLetter.Tahun = tahun1 + tahun2;
                    }
                    else
                    {
                        actLetter.Tahun = tahun1;
                    }
                }
                db.Entry(actLetter).State = EntityState.Modified;
                letterOfCommand.NomorSP   = letterno;
                foreach (var mb in members)
                {
                    letterOfCommand.MemberID += mb + ";";
                }
                letterOfCommandDetailDasar.LetterOfCommandID = letterOfCommand.LetterOfCommandID;
                letterOfCommandDetailDasar.Dasar             = null;
                foreach (var ds in dasar)
                {
                    letterOfCommandDetailDasar.Dasar += ds + ";";
                }
                letterOfCommandDetailUntuk.LetterOfCommandID = letterOfCommand.LetterOfCommandID;
                letterOfCommandDetailUntuk.Untuk             = null;
                foreach (var utk in untuk)
                {
                    letterOfCommandDetailUntuk.Untuk += utk + ";";
                }
                letterOfCommandDetailTembusan.LetterOfCommandID = letterOfCommand.LetterOfCommandID;
                letterOfCommandDetailTembusan.Tembusan          = null;
                foreach (var tmb in tembusan)
                {
                    letterOfCommandDetailTembusan.Tembusan += tmb + ";";
                }
                db.LetterOfCommandDetailDasars.Add(letterOfCommandDetailDasar);
                db.LetterOfCommandDetailTembusans.Add(letterOfCommandDetailTembusan);
                db.LetterOfCommandDetailUntuks.Add(letterOfCommandDetailUntuk);
                db.LetterOfCommands.Add(letterOfCommand);
                db.SaveChanges();
                LetterOfCommand               let         = new LetterOfCommand();
                LetterOfCommandDetailDasar    letDasar    = new LetterOfCommandDetailDasar();
                LetterOfCommandDetailUntuk    letUntuk    = new LetterOfCommandDetailUntuk();
                LetterOfCommandDetailTembusan letTembusan = new LetterOfCommandDetailTembusan();
                auditTransact.CreateAuditTrail("Create", letterOfCommand.LetterOfCommandID, "LetterOfCommand", let, letterOfCommand, username);
                auditTransact.CreateAuditTrail("Create", letterOfCommandDetailDasar.ID, "LetterOfCommandDetailDasar", letDasar, letterOfCommandDetailDasar, username);
                auditTransact.CreateAuditTrail("Create", letterOfCommandDetailUntuk.ID, "LetterOfCommandDetailUntuk", letUntuk, letterOfCommandDetailUntuk, username);
                auditTransact.CreateAuditTrail("Create", letterOfCommandDetailTembusan.ID, "LetterOfCommandDetailTembusan", letTembusan, letterOfCommandDetailTembusan, username);
                ReviewRelationMaster rrm = new ReviewRelationMaster();
                string page = "letter";
                rrm.Description = page + letterOfCommand.LetterOfCommandID;

                db.ReviewRelationMasters.Add(rrm);
                db.SaveChanges();
                TempData["message"] = "Letter Of Command successfully created!";
                return(RedirectToAction("Index"));
            }

            ViewBag.PreliminaryID = new SelectList(db.Preliminaries, "PreliminaryID", "NomorPreliminarySurvey", letterOfCommand.PreliminaryID);
            return(View(letterOfCommand));
        }