public async Task <ActionResult> DeleteConfirmed(int id) { db.Configuration.ProxyCreationEnabled = false; string username = User.Identity.Name; LetterOfCommand letterOfCommand = await db.LetterOfCommands.FindAsync(id); LetterOfCommandDetailDasar letterOfCommandDetailDasar = await db.LetterOfCommandDetailDasars.FindAsync(id); LetterOfCommandDetailTembusan letterOfCommandDetailTembusan = await db.LetterOfCommandDetailTembusans.FindAsync(id); LetterOfCommandDetailUntuk letterOfCommandDetailUntuk = await db.LetterOfCommandDetailUntuks.FindAsync(id); LetterOfCommand let = new LetterOfCommand(); LetterOfCommandDetailDasar letdasar = new LetterOfCommandDetailDasar(); LetterOfCommandDetailUntuk letuntuk = new LetterOfCommandDetailUntuk(); LetterOfCommandDetailTembusan lettembusan = new LetterOfCommandDetailTembusan(); db.LetterOfCommands.Remove(letterOfCommand); db.LetterOfCommandDetailDasars.Remove(letterOfCommandDetailDasar); db.LetterOfCommandDetailTembusans.Remove(letterOfCommandDetailTembusan); db.LetterOfCommandDetailUntuks.Remove(letterOfCommandDetailUntuk); await db.SaveChangesAsync(); auditTransact.CreateAuditTrail("Delete", id, "LetterOfCommand", letterOfCommand, let, username); auditTransact.CreateAuditTrail("Delete", id, "LetterOfCommandDasar", letterOfCommandDetailDasar, letdasar, username); auditTransact.CreateAuditTrail("Delete", id, "LetterOfCommandUntuk", letterOfCommandDetailUntuk, letuntuk, username); auditTransact.CreateAuditTrail("Delete", id, "LetterOfCommandTembusan", letterOfCommandDetailTembusan, lettembusan, username); TempData["message"] = "Letter Of Command successfully deleted!"; return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(string submit, string Status, string[] Dasar, string[] Untuk, string[] Tembusan, string activid, string memberName, string[] member, string pic, string supervisor, string leader, string nomer, [Bind(Include = "LetterOfCommandID,NomorSP,Status,Remarks,AssuranceType,Date_Start,Date_End,Menimbang,Penutup,AuditPlanningMemorandumID,ActivityID,PICID,SupervisorID,TeamLeaderID,MemberID")] LetterOfCommand letterOfCommand) { if (ModelState.IsValid) { letterOfCommand.Status = Status; 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; if (member != null) { foreach (var mb in member) { letterOfCommand.MemberID += mb + ";"; } } else { letterOfCommand.MemberID += ";"; } 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 <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; db.Configuration.ProxyCreationEnabled = false; LetterOfCommandDetailDasar letterOfCommandDetailDasar = db.LetterOfCommandDetailDasars.AsNoTracking().Where(p => p.LetterOfCommandID == letterOfCommand.LetterOfCommandID).FirstOrDefault(); LetterOfCommandDetailUntuk letterOfCommandDetailUntuk = db.LetterOfCommandDetailUntuks.AsNoTracking().Where(p => p.LetterOfCommandID == letterOfCommand.LetterOfCommandID).FirstOrDefault(); LetterOfCommandDetailTembusan letterOfCommandDetailTembusan = db.LetterOfCommandDetailTembusans.AsNoTracking().Where(p => p.LetterOfCommandID == letterOfCommand.LetterOfCommandID).FirstOrDefault(); letterOfCommandDetailDasar.LetterOfCommandID = letterOfCommand.LetterOfCommandID; letterOfCommandDetailDasar.Dasar = null; if (Dasar != null) { foreach (var ds in Dasar) { letterOfCommandDetailDasar.Dasar += ds + ";"; } } else { letterOfCommandDetailDasar.Dasar = ";"; } letterOfCommandDetailUntuk.LetterOfCommandID = letterOfCommand.LetterOfCommandID; letterOfCommandDetailUntuk.Untuk = null; if (Untuk != null) { foreach (var uk in Untuk) { letterOfCommandDetailUntuk.Untuk += uk + ";"; } } else { letterOfCommandDetailUntuk.Untuk = ";"; } letterOfCommandDetailTembusan.LetterOfCommandID = letterOfCommand.LetterOfCommandID; letterOfCommandDetailTembusan.Tembusan = null; if (Tembusan != null) { foreach (var ts in Tembusan) { letterOfCommandDetailTembusan.Tembusan += ts + ";"; } } else { letterOfCommandDetailTembusan.Tembusan = ";"; } string username = User.Identity.Name; LetterOfCommand oldData = db.LetterOfCommands.AsNoTracking().Where(p => p.LetterOfCommandID.Equals(letterOfCommand.LetterOfCommandID)).FirstOrDefault(); LetterOfCommandDetailDasar oldDataDasar = db.LetterOfCommandDetailDasars.AsNoTracking().Where(p => p.ID.Equals(letterOfCommandDetailDasar.ID)).FirstOrDefault(); LetterOfCommandDetailUntuk oldDataUntuk = db.LetterOfCommandDetailUntuks.AsNoTracking().Where(p => p.ID.Equals(letterOfCommandDetailUntuk.ID)).FirstOrDefault(); LetterOfCommandDetailTembusan oldDataTembusan = db.LetterOfCommandDetailTembusans.AsNoTracking().Where(p => p.ID.Equals(letterOfCommandDetailTembusan.ID)).FirstOrDefault(); auditTransact.CreateAuditTrail("Update", letterOfCommand.LetterOfCommandID, "LetterOfCommand", oldData, letterOfCommand, username); auditTransact.CreateAuditTrail("Update", letterOfCommandDetailDasar.ID, "LetterOfCommandDasar", oldDataDasar, letterOfCommandDetailDasar, username); auditTransact.CreateAuditTrail("Update", letterOfCommandDetailUntuk.ID, "LetterOfCommandUntuk", oldDataUntuk, letterOfCommandDetailUntuk, username); auditTransact.CreateAuditTrail("Update", letterOfCommandDetailTembusan.ID, "LetterOfCommandTembusan", oldDataTembusan, letterOfCommandDetailTembusan, username); db.Entry(letterOfCommandDetailDasar).State = EntityState.Modified; db.Entry(letterOfCommandDetailUntuk).State = EntityState.Modified; db.Entry(letterOfCommandDetailTembusan).State = EntityState.Modified; db.Entry(letterOfCommand).State = EntityState.Modified; await db.SaveChangesAsync(); TempData["message"] = "Letter Of Command successfully updated!"; return(RedirectToAction("Index")); } ViewBag.PreliminaryID = new SelectList(db.Preliminaries, "PreliminaryID", "Type", letterOfCommand.PreliminaryID); return(View(letterOfCommand)); }
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)); }