public bool ChangeUserStatus(string userMail)
        {
            bool status = true;

            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    var item = (from a in db.AspNetUsers where a.Email == userMail select a).FirstOrDefault();
                    if (item.EmailConfirmed)
                    {
                        item.EmailConfirmed = false;
                        //item.Role = (int)RoleTypes.Admin;
                    }
                    else
                    {
                        item.EmailConfirmed = true;
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(status);
        }
Пример #2
0
        public HttpResponseMessage DeleteScripts(List <Scripts> deleteScripts)
        {
            try
            {
                using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
                {
                    foreach (var item in deleteScripts)
                    {
                        var    a          = (from b in db.Scripts where b.Id == item.Id select b).FirstOrDefault();
                        string pathScript = HttpContext.Current.Server.MapPath("~/" + a.StoreLocation);
                        string imagePath  = HttpContext.Current.Server.MapPath("~/" + a.Image);
                        File.Delete(pathScript);
                        File.Delete(imagePath);
                        db.Scripts.Remove(a);
                    }
                    db.SaveChanges();
                }

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                return(response);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public void EnableDisbaleProject(string projectCode)
 {
     try
     {
         using (db = new XoriskManagementBackendEntities())
         {
             var project = (from a in db.Projects where a.Code == projectCode select a).FirstOrDefault();
             if (project != null)
             {
                 if (project.Status)
                 {
                     project.Status = false;
                 }
                 else
                 {
                     project.Status = true;
                 }
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();


            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }
            if (!user.EmailConfirmed)
            {
                context.SetError("User Id Not Confirmed", "User Id Not approved.Please Contact Admin");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            AuthenticationProperties properties = CreateProperties(user.Email);

            using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
            {
                try
                {
                    //var item = (from a in db.AspNetUsers where a.Email == context.UserName select a).FirstOrDefault();

                    //properties.Dictionary.Add("Role", Enum.GetName(typeof(RoleTypes), item.Role));
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            //    if (user.Role ==3)
            //{
            //    properties.Dictionary.Add("Role", "SuperUser");
            //}
            //else
            //{
            //    properties.Dictionary.Add("Role", "AdminUser");
            //}
            AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
        public List <Scripts> GetAllScripts()
        {
            List <Scripts> scriptData = new List <Scripts>();

            using (db = new XoriskManagementBackendEntities())
            {
                scriptData = (from b in db.Scripts

                              select new Scripts
                {
                    Id = b.Id,
                    MappedFolderPath = b.StoreLocation,
                    Name = b.Name,
                    Status = false,
                    ImagePath = Helper.siteUrl + b.Image,
                }).ToList <Scripts>();
            }

            //try
            //{
            //    //Dummy Projects Data need to replace with DB code

            //    for (int j = 1; j < 8; j++)
            //    {
            //        Script objScript = new Script();
            //        objScript.Id = j;
            //        objScript.Name = "System Scan Script " + j;
            //        objScript.MappedFolderPath = @"C:\Scripts";
            //        if (j % 2 == 0)
            //        {
            //            objScript.Status = true;

            //        }
            //        else
            //        {
            //            objScript.Status = false;
            //        }

            //        scriptData.Add(objScript);
            //    }

            //}
            //catch (Exception ex)
            //{


            //}
            return(scriptData);
        }
Пример #6
0
        public static System.Data.DataTable ExportToExcel(string rptName)
        {
            DataTable dt = null;

            try
            {
                using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
                {
                    if (rptName == "Scan")
                    {
                        List <ScanReport> dtTable = (from a in db.ScanReports select a).ToList <ScanReport>();
                        dt = ToDataTable(dtTable);
                    }
                    else if (rptName == "Project")
                    {
                        List <Project> dtTable = (from a in db.Projects select a).ToList <Project>();
                        dt = ToDataTable(dtTable);
                    }
                    return(dt);
                }
            }
            catch (Exception ex)
            {
                return(dt);
            }
            //System.Data.DataTable table = new System.Data.DataTable();
            //table.Columns.Add("ID", typeof(int));
            //table.Columns.Add("Name", typeof(string));
            //table.Columns.Add("Sex", typeof(string));
            //table.Columns.Add("Subject1", typeof(int));
            //table.Columns.Add("Subject2", typeof(int));
            //table.Columns.Add("Subject3", typeof(int));
            //table.Columns.Add("Subject4", typeof(int));
            //table.Columns.Add("Subject5", typeof(int));
            //table.Columns.Add("Subject6", typeof(int));
            //table.Rows.Add(1, "Amar", "M", 78, 59, 72, 95, 83, 77);
            //table.Rows.Add(2, "Mohit", "M", 76, 65, 85, 87, 72, 90);
            //table.Rows.Add(3, "Garima", "F", 77, 73, 83, 64, 86, 63);
            //table.Rows.Add(4, "jyoti", "F", 55, 77, 85, 69, 70, 86);
            //table.Rows.Add(5, "Avinash", "M", 87, 73, 69, 75, 67, 81);
            //table.Rows.Add(6, "Devesh", "M", 92, 87, 78, 73, 75, 72);
            //return table;
        }
        public List <AdminUser> GetAdminUserList(string userRole)
        {
            List <AdminUser> colUser = new List <AdminUser>();

            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    colUser = (from a in db.AspNetUsers select new AdminUser {
                        Username = a.UserName,
                        Email = a.Email,
                        Active = a.EmailConfirmed
                    }).ToList <AdminUser>();
                }
            }
            catch (Exception ex)
            {
            }
            return(colUser);
        }
        public bool CheckProjectCodeStatus(string projectCode)
        {
            bool status = false;

            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    var project = (from a in db.Projects where a.Code == projectCode select a).FirstOrDefault();
                    if (project != null)
                    {
                        status = project.Status;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(status);
        }
Пример #9
0
        public List <string> GetScriptFileNames(string ProjectCode)
        {
            List <string> objResult = new List <string>();
            string        pCode     = ProjectCode.Trim();

            using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
            {
                try
                {
                    objResult = (from a in db.ProjectScripts
                                 join b in db.Projects
                                 on a.ProjectId equals b.Id
                                 join c in db.Scripts on a.ScriptId equals c.Id
                                 where b.Code == pCode
                                 select c.Name).ToList <string>();
                }
                catch (Exception ex)
                {
                    throw;
                }
                return(objResult);
            }
        }
Пример #10
0
        public static bool createProjectScript(int projectID, int ScriptID, string projectCode)
        {
            bool result = false;

            try
            {
                using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
                {
                    ProjectScript obj = new ProjectScript();
                    obj.ProjectCode = projectCode;
                    obj.ProjectId   = projectID;
                    obj.ScriptId    = ScriptID;
                    obj.CreatedAt   = DateTime.Now;
                    db.ProjectScripts.Add(obj);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            return(result);
        }
Пример #11
0
        public HttpResponseMessage UpdateScanReportStatus(string projectCode, string systemIP, string startTime, string endTime, string status, string scriptName, string hostName)

        {
            using (XoriskManagementBackendEntities db = new XoriskManagementBackendEntities())
            {
                ScanReport newReport = new ScanReport();
                newReport.CreatedAt   = DateTime.Now;
                newReport.UpdatedAt   = DateTime.Now;
                newReport.ProjectCode = projectCode;
                newReport.SystemIP    = systemIP;
                DateTime s;
                DateTime.TryParse(startTime, out s);
                DateTime e;
                DateTime.TryParse(endTime, out e);
                //DateTime startDate = Helper.GetDate(startTime);
                newReport.StartTime = s;
                newReport.EndTime   = e;
                //newReport.StartTime = Helper.GetDate(startTime);
                //newReport.EndTime = Helper.GetDate(endTime);
                //newReport.StartTime = startTime;
                //newReport.EndTime = endTime;
                newReport.Status     = status;
                newReport.ScriptName = scriptName;
                newReport.SystemMAC  = hostName;
                db.ScanReports.Add(newReport);
                db.SaveChanges();

                //newReport.Status = status;
            }
            HttpResponseMessage response = new HttpResponseMessage();

            response.StatusCode = HttpStatusCode.OK;

            return(response);

            // return new string[] { "Video/Script1.vbe", "Video/Script2.vbe", "Video/Script3.vbe", "Video/Script4.vbe" };
        }
        public List <SystemScanReportModel> GetScanReport(string projectCode)
        {
            //TODO on logout from front end need to logout from server so call API from frond end
            //getLoggedIn user from session
            var customerEmail = User.Identity.Name;

            List <SystemScanReportModel> scriptData = new List <SystemScanReportModel>();

            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    if (projectCode == "All")
                    {
                        scriptData = (from a in db.ScanReports
                                      orderby a.EndTime descending
                                      select new SystemScanReportModel
                        {
                            SystemIP = a.SystemIP,
                            ProjectCode = a.ProjectCode,
                            ScanStatus = a.Status,
                            ScanStart = a.StartTime,
                            ScanEnd = a.EndTime
                        }).ToList <SystemScanReportModel>();
                    }
                    else if (projectCode == "customer")
                    {
                        var customerProjectCodes = db.Projects.Where(x => x.Email == customerEmail).ToList();
                        foreach (var project in customerProjectCodes)
                        {
                            var data = (from a in db.ScanReports
                                        where a.ProjectCode == project.Code
                                        orderby a.EndTime descending
                                        select new SystemScanReportModel
                            {
                                SystemIP = a.SystemIP,
                                ProjectCode = a.ProjectCode,
                                ScanStatus = a.Status,
                                ScanStart = a.StartTime,
                                ScanEnd = a.EndTime
                            }).ToList <SystemScanReportModel>();
                            scriptData.AddRange(data);
                        }
                    }
                    else
                    {
                        scriptData = (from a in db.ScanReports
                                      where a.ProjectCode == projectCode
                                      orderby a.EndTime descending
                                      select new SystemScanReportModel
                        {
                            SystemIP = a.SystemIP,
                            ProjectCode = a.ProjectCode,
                            ScanStatus = a.Status,
                            ScanStart = a.StartTime,
                            ScanEnd = a.EndTime
                        }).ToList <SystemScanReportModel>();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(scriptData);
        }
        public List <ProjectDetails> GetAllProjects()
        {
            List <ProjectDetails> colAllProjects = new List <ProjectDetails>();


            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    var result = (from b in db.Projects
                                  select new ProjectDetails
                    {
                        Id = b.Id,
                        Company = b.Company
                    });

                    colAllProjects = (from a in db.Projects select new ProjectDetails {
                        Id = a.Id,
                        Company = a.Company,
                        ProjectCode = a.Code,
                        StartDateTime = a.StartDate,
                        EndDateTime = a.EndDate,
                        Email = a.Email,
                        Status = a.Status,
                        POCName = a.POCName
                    }).ToList <ProjectDetails>();



                    foreach (var item in colAllProjects)
                    {
                        List <Scripts> scriptData = new List <Scripts>();
                        scriptData = (from b in db.Scripts
                                      select new Scripts
                        {
                            Id = b.Id,
                            MappedFolderPath = b.StoreLocation,
                            Name = b.Name,
                            Status = false,
                            ImagePath = Helper.siteUrl + b.Image
                        }).ToList <Scripts>();
                        List <Scripts> SelectedscriptData = new List <Scripts>();
                        SelectedscriptData = (from b in db.Scripts join c in db.ProjectScripts on b.Id equals c.ScriptId into col
                                              from c in col.DefaultIfEmpty() where c.ProjectId == item.Id
                                              select new Scripts
                        {
                            Id = b.Id,
                            MappedFolderPath = b.StoreLocation,
                            Name = b.Name,
                            // Status = c.ProjectId ? false :true
                        }).ToList <Scripts>();
                        foreach (var script in SelectedscriptData)
                        {
                            var data = (from a in scriptData where a.Id == script.Id select a).FirstOrDefault();
                            if (data != null)
                            {
                                data.Status = true;
                            }
                        }

                        item.StartDate = item.StartDateTime.ToShortDateString();
                        item.EndDate   = item.EndDateTime.ToShortDateString();
                        item.scripts   = scriptData;
                    }
                }


                //Dummy Projects Data need to replace with DB code
            }
            catch (Exception ex)
            {
            }
            return(colAllProjects);
        }
        public HttpResponseMessage PostScripts()
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();
            string filePath      = string.Empty;
            string imageFilePath = string.Empty;
            Script objScript     = new Script();

            try
            {
                var    httpRequest    = HttpContext.Current.Request;
                string MappedFileName = httpRequest.Form["MappedName"];

                foreach (string file in httpRequest.Files)
                {
                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);

                    var postedFile = httpRequest.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        //int MaxContentLength = 1024 * 1024 * 1; //Size = 1 MB
                        var ext       = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                        var extension = ext.ToLower();
                        if (file == "script")
                        {
                            filePath = HttpContext.Current.Server.MapPath("~/Video/" + postedFile.FileName);
                            postedFile.SaveAs(filePath);
                            objScript.StoreLocation = "Video/" + postedFile.FileName;
                            //objScript.Image = imageFilePath;
                        }
                        else if (file == "image")
                        {
                            imageFilePath = HttpContext.Current.Server.MapPath("~/Video/" + postedFile.FileName);
                            postedFile.SaveAs(imageFilePath);
                            objScript.Image = "Video/" + postedFile.FileName;
                            // objScript.Image = imageFilePath;
                        }
                    }

                    var message1 = string.Format("Script Uploaded Successfully.");
                    //return Request.CreateErrorResponse(HttpStatusCode.Created, message1); ;
                }
                using (db = new XoriskManagementBackendEntities())
                {
                    objScript.UpdatedAt = DateTime.Now;


                    objScript.CreatedAt = DateTime.Now;
                    objScript.Name      = MappedFileName;
                    db.Scripts.Add(objScript);
                    db.SaveChanges();
                }
                //var res = string.Format("Please Upload a image.");
                //dict.Add("error", res);
                return(Request.CreateResponse(HttpStatusCode.OK, dict));
            }
            catch (Exception ex)
            {
                var res = string.Format(ex.Message);
                dict.Add("error", res);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, dict));
            }
        }
        public HttpResponseMessage CreateNewProject(ProjectDetails dataProject)
        {
            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    Project project = new Project();
                    if (!String.IsNullOrEmpty(dataProject.StartDate))
                    {
                        //project.StartDate = Helper.GetDate(dataProject.StartDate);
                        project.StartDate = DateTime.Now;
                    }
                    if (!String.IsNullOrEmpty(dataProject.EndDate))
                    {
                        //project.EndDate = Helper.GetDate(dataProject.EndDate);
                        project.EndDate = DateTime.Now;
                    }
                    if (!String.IsNullOrEmpty(dataProject.Company))
                    {
                        project.Company = dataProject.Company;
                    }
                    if (!String.IsNullOrEmpty(dataProject.Email))
                    {
                        project.Email = dataProject.Email;
                    }
                    project.Code      = Helper.GenerateProjectCode(project.Company);
                    project.Status    = false;
                    project.POCName   = dataProject.POCName;
                    project.UpdatedAt = DateTime.Now;
                    project.CreatedAt = DateTime.Now;
                    db.Projects.Add(project);
                    db.SaveChanges();


                    //customer registration

                    var password = Helper.CreateRandomPassword(5);
                    password = "******" + password;

                    var user = new ApplicationUser()
                    {
                        UserName = project.Email, Email = project.Email
                    };

                    IdentityResult result = UserManager.Create(user, password);

                    if (!result.Succeeded)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                                                           "Customer registration failed"));
                    }


                    //make active user
                    var customer = (from a in db.AspNetUsers where a.Email == project.Email select a).FirstOrDefault();
                    customer.EmailConfirmed = true;
                    //customer.Role = (int)RoleTypes.Customer;
                    db.SaveChanges();



                    StringBuilder mailBody = new StringBuilder();
                    mailBody.Append("<p>Dear " + dataProject.POCName + ",<p>");

                    mailBody.Append("<p>Welcome to X-Link Portal of XORISK. This portal will be leveraged to collect inventory for machines that are not covered under our centralized scan for any reasons. All Inventory collected will be emailed to email ID <Insert Email ID> and optionally to XORISK if you choose to do so. All data collected is limited to inventory only and is collected/transmitted in a secure manner. You can read our policy at <Insert link> <p>");

                    mailBody.Append("<p>The Project Code assigned to your organization is " + project.Code + ". You can access X-Link at this url - <Insert URL><p>");
                    mailBody.Append("<p>For any questions, please reach out to your assigned engagement representative at XORISK.<p>");
                    mailBody.Append("<p>Thank You<p>");
                    mailBody.Append("<p>Team XORISK<p>");
                    mailBody.Append("<p>[email protected]<p>");
                    string subject = "XORISK- Code Generated for System Scan";
                    Helper.SendFilesInMail(subject, mailBody, project.Email);
                    foreach (var item in dataProject.scripts)
                    {
                        if (item.Status)
                        {
                            Helper.createProjectScript(project.Id, item.Id, project.Code);
                        }
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.Created, "Request Created"));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
            //return Request;
        }
        public bool UpdateProject(ProjectDetails dataProject)
        {
            bool status = false;

            try
            {
                using (db = new XoriskManagementBackendEntities())
                {
                    Project project = db.Projects.Find(dataProject.Id);
                    if (project != null)
                    {
                        if (!String.IsNullOrEmpty(dataProject.StartDate))
                        {
                            project.StartDate = Helper.GetDate(dataProject.StartDate);
                            //project.StartDate = Convert.tos(dataProject.StartDate);
                        }
                        if (!String.IsNullOrEmpty(dataProject.EndDate))
                        {
                            project.EndDate = Helper.GetDate(dataProject.EndDate);
                            //project.EndDate = Convert.ToDateTime(dataProject.EndDate);
                        }
                        if (!String.IsNullOrEmpty(dataProject.Company))
                        {
                            project.Company = dataProject.Company;
                        }
                        if (!String.IsNullOrEmpty(dataProject.Email))
                        {
                            project.Email = dataProject.Email;
                        }
                        project.UpdatedAt = DateTime.Now;
                        project.POCName   = dataProject.POCName;
                        //enable - disable project
                        project.Status = dataProject.Status;

                        foreach (var item in dataProject.scripts)
                        {
                            if (item.Status)
                            {
                                var projScript = (from a in db.ProjectScripts where a.ScriptId == item.Id && a.ProjectId == dataProject.Id select a).FirstOrDefault();
                                if (projScript == null)
                                {
                                    Helper.createProjectScript(dataProject.Id, item.Id, dataProject.ProjectCode);
                                }
                            }
                            else
                            {
                                var projScript = (from a in db.ProjectScripts where a.ScriptId == item.Id && a.ProjectId == dataProject.Id select a).FirstOrDefault();
                                if (projScript != null)
                                {
                                    db.ProjectScripts.Remove(projScript);
                                }
                            }
                        }
                        db.SaveChanges();
                        status = true;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            //

            return(status);
        }