Exemplo n.º 1
0
 public ActionResult Edit(Request request)
 {
     if (ModelState.IsValid)
     {
         db.Entry(request).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(request);
 }
Exemplo n.º 2
0
        public ActionResult Create(Request request)
        {
            if (ModelState.IsValid)
            {
                db.Requests.Add(request);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(request);
        }
Exemplo n.º 3
0
        public ActionResult Index(string[] trans,Request request, RequestKadivDTO requestkadiv)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var vwrequest = db.vwRequests
                                    .Where(a=>a.Username == User.Identity.Name);
                    int? check = vwrequest.Where(a => a.StartDate >= request.StartDate || a.EndDate >= request.EndDate).Select(a=>a.RequestID).FirstOrDefault();
                    if (check != 0)
                    {
                        //TempData["ModelName"] = vwrequest;
                        return RedirectToAction("NotAvailable", new { id = check });
                    }
                    //Transaction
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        vwUserProfile vwUserProfile =  db.vwUserProfiles.Where(a => a.Username == User.Identity.Name).FirstOrDefault();
                        // Declaration Variabel//
                        var StartDate = Convert.ToDateTime(request.StartDate).Date;
                        var EndDate = Convert.ToDateTime(request.EndDate).Date;
                        var PositionID = vwUserProfile.PositionID;
                        var UserID = vwUserProfile.ID;
                        var CreatedBy = User.Identity.Name;
                        var ApprovalPositionID = vwUserProfile.AssignID;
                        DateTime DateNow = DateTime.Now;
                        string hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);

                        // Maping To Request Model For New Request And Save  //
                        request.FlagID = 1;//NEW REQUEST
                        request.StartDate = StartDate;
                        request.EndDate = EndDate;
                        request.PositionID = PositionID;
                        request.UserID = UserID;
                        request.CreatedBy = CreatedBy;
                        request.CreatedDate = DateNow;
                        request.FlagCreatedDate = DateNow;
                        if (requestkadiv.sendirilain == 2)
                        {
                            request.ApprovalPositionID = vwUserProfile.PositionID;
                        }
                        if (requestkadiv.sendirilain == 0 || requestkadiv.sendirilain != 2)
                        {
                            request.ApprovalPositionID = ApprovalPositionID;
                        }

                        db.Requests.Add(request);
                        db.SaveChanges();

                        // Mapping To Request Model For New Request And Save  //
                        request.FlagID = 5;//REQUEST APPROVAL
                        db.Entry(request).State = EntityState.Modified;
                        db.SaveChanges();

                        // Mapping To RequestInTransport Model For List Transportaions And Save  //
                        foreach (var transID in trans)
                        {
                            var AdCategory = new RequestInTransport()
                            {
                                RequestID = request.RequestID,
                                TransportID = Convert.ToInt16(transID)
                            };
                            db.RequestInTransports.Add(AdCategory);
                        }
                        db.SaveChanges();

                        if (requestkadiv.ProgramID ==0)
                        {
                            //PAKE INTERNET
                            //Sending Email To Approver From Requester
                            if (ServiceSkpd.SendEmailToApproverFromRequester(hostUrl, request, db, MessengerService))
                            {
                                //Comitt If This Transaction is Success
                                transaction.Complete();
                                return RedirectToAction("Thanks", "Pengajuan");
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gagal proses pengajuan");
                                ModelState.AddModelError("", "Gagal mengirim email");
                                ModelState.AddModelError("", "Pastikan anda sedang terhubung koneksi internet");
                            }
                        }

                        //MY BUDGET
                        if (requestkadiv.sendirilain != 2)
                        {
                            //request.FlagID = 2;
                            //request.FlagCreatedDate = DateNow;
                            //db.Entry(request).State = EntityState.Modified;
                            //db.SaveChanges();

                            //request.FlagID = 5;
                            //request.ApprovalPositionID = ApprovalPositionID;
                            //request.FlagCreatedDate = DateNow;
                            //db.Entry(request).State = EntityState.Modified;
                            //db.SaveChanges();

                            RequestInProgram requestinprogram = new RequestInProgram();
                            requestinprogram.RequestID = request.RequestID;
                            requestinprogram.ProgramID = requestkadiv.ProgramID;
                            db.RequestInPrograms.Add(requestinprogram);
                            db.SaveChanges();

                            //PAKE INTERNET
                            //Sending Email To Approver From Requester
                            if (ServiceSkpd.SendEmailToApproverFromRequester(hostUrl, request, db, MessengerService))
                            {
                                //Comitt If This Transaction is Success
                                transaction.Complete();
                                return RedirectToAction("Thanks", "Pengajuan");
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gagal proses pengajuan");
                                ModelState.AddModelError("", "Gagal mengirim email");
                                ModelState.AddModelError("", "Pastikan anda sedang terhubung koneksi internet");
                            }
                            //Comitt If This Transaction is Success
                            //transaction.Complete();
                            //return RedirectToAction("Thanks", "Pengajuan");
                        }
                        else
                        {
                            request.FlagID = 2;
                            request.FlagCreatedDate = DateNow;
                            db.Entry(request).State = EntityState.Modified;
                            db.SaveChanges();

                            var AssignIDForBudget = db.vwPositionInPrograms.Where(a => a.UnitID == requestkadiv.UnitID).Select(a => a.PositionID).FirstOrDefault();
                            request.FlagID = 9;
                            request.FlagCreatedDate = DateNow;
                            request.ApprovalPositionID = AssignIDForBudget;
                            db.Entry(request).State = EntityState.Modified;
                            db.SaveChanges();

                            if (ServiceSkpd.SendEmailRequestBudgetToDivisionFromRequester(hostUrl, request, db, MessengerService))
                            {
                                transaction.Complete();
                                return RedirectToAction("SuccessSendRequestBudget");
                            }
                            else
                            {
                                ModelState.AddModelError("", "Gagal proses pengajuan");
                                ModelState.AddModelError("", "Gagal mengirim email");
                                ModelState.AddModelError("", "Pastikan anda sedang terhubung koneksi internet");
                            }
                        }
                        #region
                        ////string resetUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/PasswordReset?resetToken=" + HttpUtility.UrlEncode(resetToken));

                        //var fromFirstName = db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.FirstName).Single();
                        //var fromLastName = db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.LastName).Single();
                        //var fromfullName = string.Format("{0}.{1}", fromFirstName.ToUpper(), fromLastName.ToUpper());
                        //var fromAddress = ConfigurationManager.AppSettings["Sender"];
                        //var fromPositionName = db.Positions.Where(a => a.PositionID == request.PositionID).Select(a => a.PositionName).Single();
                        //var skpdDestination = request.Destination;
                        //var skpdStarDate = request.StartDate.Date.ToShortDateString();
                        //var skpdEventName= request.EventName;
                        //var skpdEndDate = request.EndDate.Date.ToShortDateString();
                        //var toAddress = db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Email).Single();
                        //var toName = db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Username).Single();
                        //var skpdRequestID = lastReuestID.ToString();
                        //var QueryParam = string.Format("UserName={0}&RequestID={1}", toName, skpdRequestID);
                        //var QueryParamEncrypt = ServiceSkpd.QueryStringEncrypt(QueryParam);
                        //var approveUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/Persetujuan/ApproveFromEmail{0}", QueryParamEncrypt));
                        //var rejectUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/Persetujuan/RejectFromEmail{0}", QueryParamEncrypt));
                        ////var approveUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/Persetujuan/ApproveFromEmail?UserName={0}&id={1}", HttpUtility.UrlEncode(toName), HttpUtility.UrlEncode(skpdRequestID)));
                        ////var rejectUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/Persetujuan/RejectFromEmail?UserName={0}&id={1}", HttpUtility.UrlEncode(toName), HttpUtility.UrlEncode(skpdRequestID)));
                        //var subject = string.Format("Request from {0}, for approval of official travel", fromfullName);
                        //var body = string.Format("Dear, Mr./Mrs. {0} <br /><br/>" +
                        //                        "Request for approval of official travel : " +
                        //                        "<br/><br/>RequestID: {1} " +
                        //                        "<br/>Name: {2} " +
                        //                        "<br/>Position: {3} " +
                        //                        "<br/>Destination : {4} " +
                        //                        "<br/>EventName : {5} " +
                        //                        "<br/>Star Date : {6} " +
                        //                        "<br/>End Date : {7} " +
                        //                        "<br/><br /> whether you would approve or reject this request ? " +
                        //                        "<br/><br/><p><strong><a href=\"{8}\">APPROVE</a></strong></p> " +
                        //                        "<br/><br/><p><strong><a href=\"{9}\">REJECT</a></strong></p>", toName, lastReuestID, fromfullName, fromPositionName, skpdDestination, skpdEventName, skpdStarDate, skpdEndDate, approveUrl, rejectUrl);

                        //if (MessengerService.Send(fromAddress, toAddress, subject, body, true))
                        //{
                        //    transaction.Complete();
                        //    return RedirectToAction("Thanks", "Pengajuan");
                        //}
                        //else
                        //{
                        //    ModelState.AddModelError("", "Gagal mengirim Email, kontak IT Service di wilayah anda");
                        //    return View(request);
                        //}
                    }
                }
                //catch (DbEntityValidationException dbEx)
                //{
                //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                //    {
                //        foreach (var validationError in validationErrors.ValidationErrors)
                //        {
                //            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                //            ModelState.AddModelError("", string.Format("{0} >> {1}", validationError.PropertyName, validationError.ErrorMessage));
                //        }
                //    }
                //}
                        #endregion
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return View(request);
        }
Exemplo n.º 4
0
        public bool SendEmailToApproverFromRequester(string hostUrl,Request request, ESKAPEDEContext Db,IMessengerService MessengerService)
        {
            var isSuccess = false;
            try
            {
                var RequestID = request.RequestID ;
                var fromFirstName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.FirstName).SingleOrDefault();
                var fromLastName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.LastName).SingleOrDefault();
                if (fromLastName == null) fromLastName = "";
                var fromfullName = string.Format("{0}.{1}", fromFirstName.ToUpper(), fromLastName.ToUpper());
                var fromAddress = ConfigurationManager.AppSettings["Sender"];
                var fromPositionName = Db.Positions.Where(a => a.PositionID == request.PositionID).Select(a => a.PositionName).SingleOrDefault();
                var fromDivisionName = Db.Positions.Where(a => a.PositionID  == request.PositionID).Select(a => a.Unit.Division.DivisionName).SingleOrDefault();
                var fromCountryName = Db.Positions.Where(a => a.PositionID  == request.PositionID).Select(a => a.Country.CountryName).SingleOrDefault();
                var fromDesti = Db.Countries.Where(a => a.CountryID == request.FromCountryID).Select(a => a.CountryName).SingleOrDefault();
                var toDesti = Db.Countries.Where(a => a.CountryID == request.ToCountryID).Select(a => a.CountryName).SingleOrDefault();
                var fromDate = request.StartDate.Date.ToShortDateString();
                var toDate = request.EndDate.Date.ToShortDateString();
                var skpdEventName = request.EventName;
                var skpdEndDate = request.EndDate.Date.ToShortDateString();
                var toAddress = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Email).SingleOrDefault();
                var toName = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Username).SingleOrDefault();
                var skpdRequestID = request.RequestID.ToString();
                var QueryParam = string.Format("UserName={0}&RequestID={1}", toName, skpdRequestID);
                var QueryParamEncrypt = QueryStringEncrypt(QueryParam);
                var approveUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/FromEmail/Approve{0}", QueryParamEncrypt));
                var rejectUrl = hostUrl + VirtualPathUtility.ToAbsolute(string.Format("~/FromEmail/Reject{0}", QueryParamEncrypt));
                var subject = string.Format("Pengajuan Permohonan Perjalanan Dinas Dari Bapak/Ibu {0}", fromfullName);
                IEnumerable<RequestInTransport> ListTrans = Db.RequestInTransports.Include("Transport").Where(a => a.RequestID == request.RequestID);
                var anggaran = Db.RequestInPrograms.Where(a => a.RequestID == request.RequestID).Select(a => a.Program.ProgramName).FirstOrDefault();

                //IEnumerable<Transport> transport = db.Transports;
                var StrListTrans = "<ul>";
                foreach (var item in ListTrans)
                {
                    StrListTrans += string.Format("<li>{0}</li>", item.Transport.TransportName);
                }
                StrListTrans = string.Format("{0}</ul>", StrListTrans);

                var body = string.Format("Kepada Yth,<br />" +
                                        "Bapak/Ibu. {0} <br /><br/>" +
                                        "Permohonan Persetujuan Perjalanan Dinas : " +
                                        "<br/><br/>No. Perjadin: {1} " +
                                        "<br/>Nama: {2} " +
                                        "<br/>Posisi: {3} " +
                                        "<br/>Divisi : {4} " +
                                        "<br/>Kantor : {5} " +
                                        "<br/>Kegiatan : {6} " +
                                        "<br/>Perjalanan : {7} - {8} " +
                                        "<br/>Tanggal: {9} - {10}" +
                                        "<br/>Transportasi : {11} " +
                                        "<br/>Beban Anggaran : {12} " +
                                        "<br/><br /> Apakah Permohonan perjalanan dinas ini di SETUJUI atau TIDAK DISETUJUI ? " +
                                        "<br/><br/><p><strong><a href=\"{13}\">DISETUJUI</a></strong></p> " +
                                        "<br/><br/><p><strong><a href=\"{14}\">TIDAK DISETUJUI</a></strong></p>",
                                        toName.ToUpper(), skpdRequestID, fromfullName, fromPositionName, fromDivisionName,
                                        fromCountryName, skpdEventName, fromDesti, toDesti, fromDate, toDate,
                                        StrListTrans, anggaran, approveUrl, rejectUrl);

                if (MessengerService.Send(fromAddress, toAddress, subject, body, true))
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                //Log exception
                ex.ToString();
            }

            return isSuccess;
        }
Exemplo n.º 5
0
        public bool SendEmailResultToRequesterCcApprover(Request request, ESKAPEDEContext Db, IMessengerService MessengerService)
        {
            var isSuccess = false;
            try
            {
                //SEND EMAIL TO REQUESTER Cc APPROVER
                var RequestID = request.RequestID.ToString();
                var fromFirstName = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.FirstName).SingleOrDefault();
                var fromLastName = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.LastName).SingleOrDefault();
                if (fromLastName == null) fromLastName = "";
                var fromfullName = string.Format("{0}.{1}", fromFirstName.ToUpper(), fromLastName.ToUpper());
                var toFirstName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.FirstName).SingleOrDefault();
                var toLastName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.LastName).SingleOrDefault();
                var tofullName = string.Format("{0}.{1}", toFirstName.ToUpper(), toLastName.ToUpper());
                var fromAddress = ConfigurationManager.AppSettings["Sender"];
                var toAddress = Db.Users.Where(a => a.ID == request.UserID).Select(a => a.Email).SingleOrDefault();
                var ccAddress = ccEmail(request.RequestID);
                var subject = string.Format("Hasil Pengajuan Perjalanan Dinas Dari {0}", tofullName);
                var appSkpdUrl = ConfigurationManager.AppSettings["hostUrl"];
                var body = string.Format("<p>Kepada Yth,<br /> Bapak/Ibu {0}<br /><br />" +
                                        "<p>No. Perjadin : {1}</p> <br />" +
                                        "<p>Pengajuan perjalanan dinas anda telah DISETUJUI oleh Bapak/Ibu {2}</p><br />" +
                                        "<p>Untuk informasi lengkap <a href=\"{3}\">login</a></p>",
                                        tofullName.ToUpper(), RequestID, fromfullName, appSkpdUrl);

                if (MessengerService.Send(fromAddress, toAddress, subject, body, true, ccAddress))
                {
                    isSuccess = true;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            return isSuccess;
        }
Exemplo n.º 6
0
        //public bool ExclusiveApprover(int ApprovalPositionID)
        //{
        //    var ApprovalPositionName = "";
        //    bool PositionName = false;
        //    string[] Exclusive;
        //    Exclusive = new string[2];
        //    Exclusive[0] = "KADIV";
        //    Exclusive[1] = "KA. KPM";
        //    List<string> _Exclusive = new List<string>(Exclusive);
        //    using (var db = new ESKAPEDEContext())
        //    {
        //        ApprovalPositionName = db.Positions.Where(a => a.PositionID == ApprovalPositionID).Select(a => a.PositionName).First();
        //    }
        //    if (_Exclusive.Any(s => ApprovalPositionName.Contains(s)))
        //    {
        //        PositionName = true;
        //    }
        //    return PositionName;
        //}
        public bool SendEmailRejectToRequesterCcApprover(Request request, ESKAPEDEContext Db, IMessengerService MessengerService)
        {
            var isSuccess = false;
            try
            {
                var RequestID = request.RequestID;
                var fromUsername = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Username).SingleOrDefault();
                var fromFirstName = Db.Users.Where(a => a.Username == fromUsername).Select(a => a.FirstName).SingleOrDefault();
                var fromLastName = Db.Users.Where(a => a.Username == fromUsername).Select(a => a.LastName).SingleOrDefault();
                if (fromLastName == null) fromLastName = "";
                var fromfullName = string.Format("{0}.{1}", fromFirstName.ToUpper(), fromLastName.ToUpper());
                var fromAddress = ConfigurationManager.AppSettings["Sender"];
                var toAddress = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Email).SingleOrDefault();
                var toFirstName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.FirstName).SingleOrDefault();
                var toLastName = Db.Users.Where(a => a.Username == request.CreatedBy).Select(a => a.LastName).SingleOrDefault();
                var tofullName = string.Format("{0}.{1}", toFirstName.ToUpper(), toLastName.ToUpper());
                //var ccAddress = Db.Users.Where(a => a.PositionID == request.ApprovalPositionID).Select(a => a.Email).Single();
                var ccAddress = ccEmail(request.RequestID);
                var subject = string.Format("Hasil Permohonan Pengajuan Perjalan Dinas Dari {0}", fromfullName);
                var appSkpdUrl = ConfigurationManager.AppSettings["hostUrl"];
                var fromReason = request.RejectedReason;
                var body = string.Format("<p>Kepada Yth,<br />" +
                                        "Bapak/Ibu {0}<br /><br />" +
                                        "No. Perjadin : {1} <br />" +
                                        "TIDAK DISETUJUI Oleh Bapak/Ibu {2}</p><br />" +
                                        "Dengan Alasan : {3}" +
                                        "<p>Untuk informasi lengkap <a href='{4}'>login</a></p>",
                                        tofullName.ToUpper(), RequestID, fromfullName, request.RejectedReason, appSkpdUrl);
                if (MessengerService.Send(fromAddress, toAddress, subject, body, true, ccAddress))
                {
                    isSuccess = true;
                }

            }
            catch (Exception ex)
            {
                //Log exception
                ex.ToString();
            }

            return isSuccess;
        }