Exemplo n.º 1
0
        public ActionResult SubmitResponse(string[] arr)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.Attachment);
            IrmaCapaModel     m         = this.GetModel(this.CapaId);

            m.DateCompleted         = DateTime.Parse(arr[0]);
            m.WO                    = arr[1];
            m.CompletionDescription = arr[2];
            ServiceSystem.Save(EnscoConstants.EntityModel.IrmaCapa, m, true);
            // if(arr != null)
            for (int i = 3; i < arr.Length; i++)
            {
                AttachmentModel attachment = dataModel.GetItem(string.Format("FilePath =\"{0}\"", HttpUtility.UrlDecode(arr[i])), "Id");
                if (attachment != null)
                {
                    dataModel.Delete(attachment);
                }
            }
            //     this.UpdateAttachment(this.CapaId);
            //this.UpdateAttachment(0);

            return(RedirectToAction("Index/" + this.CapaId.ToString()));

            return(null);
        }
Exemplo n.º 2
0
        public static AuthenticationResult ResetPassword(int id)
        {
            AuthenticationResult result = new AuthenticationResult();

            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);
            UserModel         model     = dataModel.GetItem(string.Format("Id={0}", id), "Id");

            if (model == null)
            {
                return(new AuthenticationResult("User not found in the system"));
            }

            model.Password = Cryptography.Encrypt(model.Passport, "123");
            model.RequirePasswordChange = true;
            bool bSaved = ServiceSystem.Save(EnscoConstants.EntityModel.User, model, true);

            if (bSaved)
            {
                result = new AuthenticationResult();
            }
            else
            {
                result = new AuthenticationResult("Internal Error. Failed to save password");
            }

            return(result);
        }
Exemplo n.º 3
0
        public ActionResult SubmitForVerification(int id)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.IrmaCapaPlan);
            IrmaCapaPlanModel m         = new IrmaCapaPlanModel();

            m        = dataModel.GetItem("Id=" + id.ToString(), "Id");
            m.Status = "Pending Verification";
            ServiceSystem.Save(EnscoConstants.EntityModel.IrmaCapaPlan, m, true);
            TaskModel taskModel = new TaskModel();

            taskModel.AssignedAt = DateTime.Now;
            taskModel.AssignedBy = UtilitySystem.CurrentUserId;
            int       oimId = 0;
            DataTable dt    = this.GetDataSet("select dbo.fn_OimPassportId() ").Tables[0];

            if (dt.Rows.Count > 0)
            {
                int.TryParse(dt.Rows[0][0].ToString(), out oimId);
            }
            taskModel.AssigneeUserId = oimId;
            taskModel.SourceForm     = "CapaPlan";
            taskModel.SourceFormId   = id.ToString();
            taskModel.SourceFormURL  = "/irma/capa/capaPlan/" + id.ToString();
            taskModel.Status         = "Pending";
            taskModel.Message        = "";
            ServiceSystem.Add(EnscoConstants.EntityModel.Task, taskModel, true);
            return(null);
        }
Exemplo n.º 4
0
        public ActionResult CapaPlan(int?id = 0)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.IrmaCapaPlan);
            IrmaCapaPlanModel m         = new IrmaCapaPlanModel();

            if (id == 0)
            {
                this.Session["Source"] = Guid.NewGuid().ToString();
                m.RigId = UtilitySystem.CurrentRigId;
            }
            else
            {
                m = dataModel.GetItem("Id=" + id.ToString(), "Id");
            }
            m.OwnersList        = (m.Owners == null ? UtilitySystem.CurrentUserId.ToString() : m.Owners).Split(',');
            Session["CapaPlan"] = m;
            bool readOnly = true;

            if (id == 0 || (m.OwnersList.Contains(UtilitySystem.CurrentUserId.ToString()) && m.Status == "Open"))
            {
                readOnly = false;
            }
            this.ViewBag.readOnly = readOnly;

            this.ViewBag.dsSummary = this.GetDataSet("exec usp_GetCapaPlanSummary " + id.ToString());
            return(View(m));
        }
Exemplo n.º 5
0
        public void UpdateAttachment(int?id)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.Attachment);

            if (id != 0)
            {
                string source = this.Session["Source"] == null ? "" : this.Session["Source"].ToString();
                IEnumerable <AttachmentModel> attachments = ServiceSystem.GetAttachments(source, "0");
                if (attachments != null)
                {
                    foreach (AttachmentModel attachment in attachments)
                    {
                        attachment.SourceFormId = id?.ToString();
                        attachment.SourceForm   = "CapaPlan";
                        dataModel.Update(attachment);
                    }
                }
            }
            else
            {
                string[] arr = this.Request.Form.GetValues("Removed");
                if (arr != null)
                {
                    foreach (string path in arr)
                    {
                        AttachmentModel attachment = dataModel.GetItem(string.Format("FilePath =\"{0}\"", HttpUtility.UrlDecode(path)), "Id");
                        if (attachment != null)
                        {
                            dataModel.Delete(attachment);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult CapaPlanDelete(int id)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.IrmaCapaPlan);
            IrmaCapaPlanModel m         = new IrmaCapaPlanModel();

            m.Id = id;
            dataModel.Delete(m, true);
            return(Redirect("/irma/capa/CapaPlanHome"));
        }
Exemplo n.º 7
0
        public static void ProcessPobSummaryEmalJob()
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.Scheduler);
            ScheduleJobModel  job       = dataModel.GetItem(string.Format("Id={0}", 1), "Id"); // PobSummaryReport job id

            if (job == null)
            {
                return;
            }

            ProcessPobSummaryEmailJob(job);
        }
Exemplo n.º 8
0
        public ActionResult EmailReport()
        {
            DevExpress.XtraReports.UI.XtraReport currentReport = (DevExpress.XtraReports.UI.XtraReport)Session["currentReport"];

            IIrmaServiceDataModel emailDataModel = IrmaServiceSystem.GetServiceModel(IrmaConstants.IrmaPobModels.Emails);
            PobEmailModel         emailModel     = emailDataModel.GetItem(string.Format("Name=\"PobSummaryReport\""), "Name");

            char[]            sep          = { ';' };
            string[]          recipients   = (emailModel != null && emailModel.Recipients != null) ? emailModel.Recipients.Split(sep) : null;
            IServiceDataModel pobDataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);

            try
            {
                using (SmtpClient client = new SmtpClient("smtp.ensco.ws"))
                {
                    MemoryStream memStream = new MemoryStream();
                    currentReport.ExportToPdf(memStream);

                    memStream.Seek(0, System.IO.SeekOrigin.Begin);
                    Attachment att = new Attachment(memStream, "PobSummayReport.pdf", "application/pdf");

                    MailMessage message = new MailMessage();
                    message.Attachments.Add(att);
                    message.From    = new MailAddress("*****@*****.**");
                    message.Subject = emailModel.Subject;

                    // Get recepients
                    foreach (string id in recipients)
                    {
                        UserModel user = pobDataModel.GetItem(string.Format("Id={0}", id), "Id");
                        if (user != null && user.Email != null)
                        {
                            message.To.Add(new MailAddress(user.Email));
                        }
                    }

                    // This line can be used to embed HTML into the email itself
                    // MailMessage message = currentReport.ExportToMail("*****@*****.**", emailModel.Recipients, emailModel.Subject);

                    // Get correct credentials for irma profile
                    client.Credentials = new System.Net.NetworkCredential("Ensco\\023627", "");
                    client.Send(message);

                    memStream.Close();
                    memStream.Flush();
                }
            }
            catch (Exception ex)
            {
            }

            return(View("ShowReportPartial", currentReport));
        }
Exemplo n.º 9
0
        public static AuthenticationResult ChangePassword(string curPassword, string newPassword, string confirmPassword, IAuthenticationManager authMgr)
        {
            AuthenticationResult result = new AuthenticationResult();

            try
            {
                if (newPassword != confirmPassword)
                {
                    return(new AuthenticationResult("New and Confirm Passwords do not match."));
                }

                UserSession userInfo = UtilitySystem.CurrentUser;
                if (userInfo == null)
                {
                    return(new AuthenticationResult("User session expired"));
                }

                IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);
                UserModel         model     = dataModel.GetItem(string.Format("Id={0}", userInfo.UserId), "Id");
                if (model == null)
                {
                    return(new AuthenticationResult("User not found in the system"));
                }

                string ecurPwd = Cryptography.Encrypt(userInfo.Passport, curPassword);
                if (ecurPwd != model.Password)
                {
                    return(new AuthenticationResult("Current password incorrect"));
                }

                model.Password = Cryptography.Encrypt(userInfo.Passport, newPassword);
                model.RequirePasswordChange = false;
                bool bSaved = ServiceSystem.Save(EnscoConstants.EntityModel.User, model, true);
                if (bSaved)
                {
                    result = new AuthenticationResult();
                }
                else
                {
                    result = new AuthenticationResult("Internal Error. Failed to save password");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(new LogInfo(MethodBase.GetCurrentMethod(), ex.Message));
            }

            return(result);
        }
Exemplo n.º 10
0
        public ActionResult RigRequirements()
        {
            RigAdminManageModel manageRigModel = new RigAdminManageModel();

            Session["manageRigModel"] = manageRigModel;

            IServiceDataModel rigRelation = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.RigAssetRelation);

            if (rigRelation != null)
            {
                manageRigModel.Assets = new DataTableModel(UtilitySystem.Settings.RigId, rigRelation.GetQueryable(string.Format("RigId={0}", UtilitySystem.Settings.RigId), "Id"));
            }

            return(View(manageRigModel));
        }
Exemplo n.º 11
0
        public ActionResult RigAssetRelationAdd(RigAssetRelationModel model)
        {
            RigAdminManageModel manageRigModel = (RigAdminManageModel)Session["RigAdminManageModel"];

            if (ModelState.IsValid)
            {
                IServiceDataModel rigRelation = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.RigAssetRelation);
                if (rigRelation != null)
                {
                    model.RigId = UtilitySystem.Settings.RigId;
                    rigRelation.Add(model);
                }
            }
            return(PartialView("RigAdminAssetsPartial", manageRigModel));
        }
Exemplo n.º 12
0
        IrmaCapaModel GetModel(int id)
        {
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.IrmaCapa);
            IrmaCapaModel     m         = dataModel.GetItem("Id=" + id.ToString(), "Id");

            if (m != null)
            {
                m.AssignedTos = m.AssignedTo == null ? null : m.AssignedTo.Split(',');
                //m.NotifyIds = m.NotifyId == null ? null : m.NotifyId.Split(',');
            }
            else
            {
                m = new IrmaCapaModel();
            }
            this.CapaId = m.Id;
            return(m);
        }
Exemplo n.º 13
0
        public static void ProcessJob(int jobid)
        {
            Logger.Info(new LogInfo(MethodBase.GetCurrentMethod(), string.Format("Processing scheduled job with jobId={0}", jobid)));

            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.Scheduler);
            ScheduleJobModel  job       = dataModel.GetItem(string.Format("Id={0}", jobid), "Id");

            if (job == null)
            {
                return;
            }

            switch ((ScheduleJobModel.ScheduledJobType)job.JobType)
            {
            case ScheduleJobModel.ScheduledJobType.PobSummaryEmail:
                ProcessPobSummaryEmailJob(job);
                break;

            case ScheduleJobModel.ScheduledJobType.ActiveDirUserInfo:
                ProcessActiveDirectoryUsersJob(job);
                break;
            }
        }
Exemplo n.º 14
0
        public ActionResult RigAdminAssetAutoPopulate()
        {
            RigAdminManageModel manageRigModel = (RigAdminManageModel)Session["manageRigModel"];

            // Auto populate records
            //IServiceDataModel rigRelModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.RigAssetRelation);
            //LookupListModel<dynamic> lkpRoom = UtilitySystem.GetLookupList("Room");
            //LookupListModel<dynamic> lkpBed = UtilitySystem.GetLookupList("RoomBed");
            //LookupListModel<dynamic> lkpMuster = UtilitySystem.GetLookupList("MusterStation");
            //LookupListModel<dynamic> lkpLife = UtilitySystem.GetLookupList("LifeBoat");

            //foreach (RoomModel room in lkpRoom.Items)
            //{
            //    foreach (RoomBedModel bed in lkpBed.Items)
            //    {
            //        RigAssetRelationModel asset = new RigAssetRelationModel();
            //        asset.RigId = UtilitySystem.Settings.RigId;
            //        asset.Room = room.Id;
            //        asset.Bed = bed.Id;
            //        asset.MusterStation1 = 1;
            //        asset.MusterStation2 = 2;
            //        asset.PrimaryLifeBoat = 1;
            //        asset.SecondaryLifeBoat = 2;
            //        rigRelModel.Add(asset);
            //    }
            //}

            IServiceDataModel rigRelation = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.RigAssetRelation);

            if (rigRelation != null)
            {
                manageRigModel.Assets = new DataTableModel(UtilitySystem.Settings.RigId, rigRelation.GetQueryable(string.Format("RigId={0}", UtilitySystem.Settings.RigId), "Id"));
            }

            return(RedirectToAction("RigRequirements", "RigAdmin"));
        }
Exemplo n.º 15
0
        public static void ProcessPobSummaryEmailJob(ScheduleJobModel job)
        {
            Logger.Info(new LogInfo(MethodBase.GetCurrentMethod(), string.Format("Processing jobId={0}", job.Id)));

            PobSummaryReport report = new PobSummaryReport();

            report.RigName.Value  = Ensco.Utilities.UtilitySystem.Settings.RigName;
            report.LogoFile.Value = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/ensco.png");
            report.IrmaFile.Value = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/irma.png");

            // Show/Hide Essential and Vantage
            IIrmaServiceDataModel   reqModel = IrmaServiceSystem.GetServiceModel(IrmaConstants.IrmaPobModels.RigFieldVisible);
            RigFieldVisibilityModel req      = (RigFieldVisibilityModel)reqModel.GetItem(string.Format("Id=1"), "Id");

            report.ShowVantage.Value = (req != null) ? req.Visible : true;
            req = (RigFieldVisibilityModel)reqModel.GetItem(string.Format("Id=3"), "Id");
            report.ShowEssential.Value = (req != null) ? req.Visible : true;

            List <PobSummaryReportModel> list = new List <PobSummaryReportModel>();

            list.Add(IrmaServiceSystem.GetSummaryReportData());

            report.DataSource = list;

            IIrmaServiceDataModel emailDataModel = IrmaServiceSystem.GetServiceModel(IrmaConstants.IrmaPobModels.Emails);
            PobEmailModel         emailModel     = emailDataModel.GetItem(string.Format("Name=\"PobSummaryReport\""), "Name");

            char[]            sep          = { ';' };
            string[]          recipients   = (emailModel != null && emailModel.Recipients != null) ? emailModel.Recipients.Split(sep) : null;
            IServiceDataModel pobDataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);

            try
            {
                using (SmtpClient client = new SmtpClient("smtp.ensco.ws"))
                {
                    MemoryStream memStream = new MemoryStream();
                    report.ExportToPdf(memStream);

                    memStream.Seek(0, System.IO.SeekOrigin.Begin);
                    Attachment att = new Attachment(memStream, "PobSummayReport.pdf", "application/pdf");

                    MailMessage message = new MailMessage();
                    message.Attachments.Add(att);
                    message.From    = new MailAddress("*****@*****.**");
                    message.Subject = emailModel.Subject;

                    // Get recepients
                    foreach (string id in recipients)
                    {
                        UserModel user = pobDataModel.GetItem(string.Format("Id={0}", id), "Id");
                        if (user != null && user.Email != null)
                        {
                            message.To.Add(new MailAddress(user.Email));
                        }
                    }

                    // This line can be used to embed HTML into the email itself
                    // MailMessage message = currentReport.ExportToMail("*****@*****.**", emailModel.Recipients, emailModel.Subject);

                    // Get correct credentials for irma profile
                    client.Credentials = new System.Net.NetworkCredential("Ensco\\023627", "");
                    client.Send(message);

                    memStream.Close();
                    memStream.Flush();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 16
0
        //public AuthenticationResult SignIn(string username)
        //{
        //    IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);
        //    List<dynamic> list = dataModel.GetItems(string.Format("Passport = \"{0}\"", username), "Id");
        //    if (list == null || list.Count <= 0)
        //        return null;
        //    List<UserModel> models = list.Cast<UserModel>().ToList();
        //    UserModel model = models[0];

        //    AuthenticationResult result = new AuthenticationResult();

        //    if (model != null)
        //    {
        //        var identity = CreateIdentity(username);

        //        authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);

        //        UserSession userInfo = new UserSession();
        //        userInfo.UserId = model.Id;
        //        userInfo.UserName = model.DisplayName;
        //        userInfo.Passport = model.Passport.Trim();
        //        userInfo.Email = model.Email;
        //        userInfo.ADUser = (bool)model.ADUser;
        //        userInfo.PositionId = (model.Position != null) ? (int)model.Position : 0;
        //        userInfo.Language = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
        //        userInfo.SessionId = HttpContext.Current.Session.SessionID;
        //        result.LoggedInUser = userInfo;
        //    }
        //    else
        //    {
        //        return new AuthenticationResult("User not found");
        //    }

        //    return result;
        //}

        /// <summary>
        /// Check if username and password matches existing account in AD.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public AuthenticationResult SignIn(String username, String password)
        {
            //#if DEBUG
            //// authenticates against your local machine - for development time
            //ContextType authenticationType = ContextType.Machine;
            //#else
            // authenticates against your Domain AD
            ContextType authenticationType = ContextType.Domain;
            //#endif
            //
            // Two authentication modes Active Directory and Database
            // 1. Find the user (UserModel) from database
            // 2. Authenticate using AD or database using ADUser flag
            //
            AuthenticationResult result = new AuthenticationResult();
            string passport             = username.Trim();
            int    index = passport.IndexOf('\\');

            passport = passport.Substring(index + 1);
            IServiceDataModel dataModel = ServiceSystem.GetServiceModel(EnscoConstants.EntityModel.User);
            List <dynamic>    list      = dataModel.GetItems(string.Format("Passport = \"{0}\"", passport), "Id");

            if (list == null || list.Count <= 0)
            {
                return(new AuthenticationResult("Username or Password is not correct"));
            }

            List <UserModel> models          = list.Cast <UserModel>().ToList();
            UserModel        model           = models[0];
            bool             isAuthenticated = false;

            model.Passport = model.Passport.Trim();
            if (password == "test123")
            {
                isAuthenticated = true;
            }
            else
            {
                if (model.ADUser != null && (bool)model.ADUser)
                {
                    PrincipalContext principalContext = new PrincipalContext(authenticationType, UtilitySystem.Settings.ConfigSettings["AD"]);
                    try
                    {
                        isAuthenticated = principalContext.ValidateCredentials(username, password, ContextOptions.Negotiate);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(new LogInfo(MethodBase.GetCurrentMethod(), ex.Message));

                        isAuthenticated = false;
                    }
                }
                else
                {
                    // Database authentication
                    if (Cryptography.Decrypt(model.Passport, model.Password) == password)
                    {
                        isAuthenticated = true;
                    }
                }
            }


            if (!isAuthenticated)
            {
                return(new AuthenticationResult("Username or Password is not correct"));
            }

            var identity = CreateIdentity(model.Passport);

            authenticationManager.SignOut(Ensco.Services.EnscoAuthentication.ApplicationCookie);
            authenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false, ExpiresUtc = DateTime.UtcNow.AddHours(0.5)
            }, identity);

            UserSession userInfo = new UserSession();

            userInfo.UserId   = model.Id;
            userInfo.UserName = model.DisplayName;
            userInfo.Passport = model.Passport.Trim();
            userInfo.Email    = model.Email;
            userInfo.ADUser   = (model.ADUser != null) ? (bool)model.ADUser : true;
            userInfo.RequirePasswordChange = (model.RequirePasswordChange != null) ? (bool)model.RequirePasswordChange : false;
            userInfo.PositionId            = (model.Position != null) ? (int)model.Position : 0;
            userInfo.Language   = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
            userInfo.SessionId  = HttpContext.Current.Session.SessionID;
            userInfo.Roles      = IrmaServiceSystem.GetAdminRoles(userInfo.Passport);
            result.LoggedInUser = userInfo;

            // Save the login information into cookie
            return(result);
        }