Esempio n. 1
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 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);
        }
 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;
     }
 }
Esempio n. 4
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);
        }
Esempio n. 5
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 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);
        }