Example #1
0
        public ActionResult ProcessRole(Role role, int id, string mode)
        {
            var dbcontext = new InlaksBIContext();

            switch (mode)
            {
            case "create":
                dbcontext.Roles.Add(role);
                dbcontext.SaveChanges();
                break;

            case "edit":
                var old = dbcontext.Roles.FirstOrDefault(t => t.RoleID == id);
                old.RoleName = role.RoleName;
                dbcontext.SaveChanges();

                break;

            case "delete":
                var item = dbcontext.Roles.FirstOrDefault(t => t.RoleID == id);
                dbcontext.Roles.Remove(item);

                dbcontext.SaveChanges();
                break;
            }


            return(RedirectToAction("RoleSetup", new { id = 0, mode = "list" }));
        }
Example #2
0
        public ActionResult ProcessMigration(Migration_Schedule schedule, int id, string mode)
        {
            var dbcontext = new InlaksBIContext();

            //schedule.MaxDate = Request.Form["MaxDate"];
            if (!string.IsNullOrEmpty(schedule.MaxDate))
            {
                schedule.MaxDate = DateTime.ParseExact(schedule.MaxDate, "dd-MM-yyyy", new System.Globalization.CultureInfo("en-US")).ToString("dd MMM yyyy");
            }

            switch (mode)
            {
            case "create":

                dbcontext.MigrationSchedules.Add(schedule);
                dbcontext.SaveChanges();
                break;

            case "edit":
                var old = dbcontext.MigrationSchedules.FirstOrDefault(t => t.ID == id);
                old.DateFilter          = schedule.DateFilter;
                old.Application_Name    = schedule.Application_Name;
                old.FetchSize           = schedule.FetchSize;
                old.MaxDate             = schedule.MaxDate;
                old.Time                = schedule.Time;
                old.Fields              = schedule.Fields;
                old.Status              = schedule.Status;
                old.Interval            = schedule.Interval;
                old.IntervalDescription = schedule.IntervalDescription;
                old.AllowWeekends       = schedule.AllowWeekends;

                //dbcontext.MigrationSchedules.Remove(old);
                // dbcontext.MigrationSchedules.Add(schedule);
                dbcontext.SaveChanges();

                break;

            case "delete":
                var item = dbcontext.MigrationSchedules.FirstOrDefault(t => t.ID == id);
                dbcontext.MigrationSchedules.Remove(item);

                dbcontext.SaveChanges();
                break;
            }


            return(RedirectToAction("MigrationSetup", new { id = 0, mode = "list" }));
        }
Example #3
0
        public ActionResult ProcessResource(Resource resource, int id, string mode)
        {
            var dbcontext = new InlaksBIContext();

            //schedule.MaxDate = Request.Form["MaxDate"];
            try
            {
                switch (mode)
                {
                case "create":
                    var re = dbcontext.Resources.Create();

                    re.Module       = dbcontext.Modules.FirstOrDefault(m => m.ModuleID == resource.ModuleID);
                    re.ResourceName = resource.ResourceName;
                    re.SubMenus     = resource.SubMenus;
                    re.value        = resource.value;
                    re.Url          = resource.Url;
                    dbcontext.Resources.Add(re);
                    dbcontext.SaveChanges();
                    break;

                case "edit":
                    var old = dbcontext.Resources.FirstOrDefault(t => t.ResourceID == id);
                    resource.Module = dbcontext.Modules.FirstOrDefault(m => m.ModuleID == resource.ModuleID);
                    dbcontext.Resources.Remove(old);
                    dbcontext.Resources.Add(resource);
                    dbcontext.SaveChanges();

                    break;

                case "delete":
                    var item = dbcontext.Resources.FirstOrDefault(t => t.ResourceID == id);
                    dbcontext.Resources.Remove(item);

                    dbcontext.SaveChanges();
                    break;
                }


                return(RedirectToAction("ResourceSetup", new { id = 0, mode = "list" }));
            }
            catch (Exception d)
            {
                return(RedirectToAction("ResourceSetup", new { id = 0, mode = "list" }));
            }
        }
Example #4
0
        public ActionResult ProcessModule(Module module, int id, string mode)
        {
            try
            {
                var dbcontext = new InlaksBIContext();
                module.Industry  = dbcontext.Industries.FirstOrDefault(i => i.IndustryID == module.IndustryID);
                module.IconClass = "glyphicon glyphicon-list";
                switch (mode)
                {
                case "create":
                    // module.ModuleID = id;
                    dbcontext.Modules.Add(module);
                    dbcontext.SaveChanges();
                    ViewBag.errorclass = "green";
                    ViewBag.message    = "Module Created successfully";
                    break;

                case "edit":
                    var old = dbcontext.Modules.FirstOrDefault(t => t.ModuleID == id);
                    old.ModuleName = module.ModuleName;
                    old.value      = module.value;
                    old.Industry   = module.Industry;
                    dbcontext.SaveChanges();
                    ViewBag.errorclass = "green";
                    ViewBag.message    = "Module modified successfully";
                    break;

                case "delete":
                    var item = dbcontext.Modules.FirstOrDefault(t => t.ModuleID == id);
                    dbcontext.Modules.Remove(item);

                    dbcontext.SaveChanges();
                    ViewBag.message    = "Module deleted successfully";
                    ViewBag.errorclass = "green";
                    break;
                }
            }
            catch (Exception e)
            {
                ViewBag.errorclass = "red";
                ViewBag.message    = "Operation failed. Please seek technical assistance";
            }

            return(RedirectToAction("ModuleSetup", new { id = 0, mode = "create" }));
        }
Example #5
0
        public string ProcessReport()
        {
            try
            {
                //  var profittable = getProfitabilityTable(0);
                var db = new InlaksBIContext();

                var dataset       = Request.Form["dataset"];
                var filtersstring = Request.Form["filters"];

                // var IsInteractive = Request.Form["IsInteractive"].Equals("1");

                var filters = JsonConvert.DeserializeObject <List <DataSetFilter> >(filtersstring);

                var pivotconfig = Request.Form["pivotconfig"];

                var resourceid = Request.Form["resourceid"].toInt();

                var resource = db.Resources.FirstOrDefault(r => r.ResourceID == resourceid);

                var prevreport = db.ResourceReports.FirstOrDefault(r => r.Resource.ResourceID == resource.ResourceID);

                var report = prevreport.isNull() ? new ResourceReport() : prevreport;

                report.Resource    = resource;
                report.pivotConfig = pivotconfig;
                report.InstanceID  = Guid.NewGuid().ToString();
                report.dataSet     = dataset;

                //foreach(var filter in filters)
                //{
                //    filter.Report = report;

                //}

                if (prevreport.isNull())
                {
                    report.Filters = filters;
                    db.ResourceReports.Add(report);
                }
                else
                {
                    var prefilters = db.DataSetFilters.Where(f => f.Report.ReportID == report.ReportID);
                    db.DataSetFilters.RemoveRange(prefilters);
                    report.Filters = filters;
                }

                db.SaveChanges();

                return("Report Saved and Published Successfully");
            }
            catch (Exception d)
            {
                return("Error encountered while saving and publishing report. Please contact Admin");
            }
        }
Example #6
0
        public string DeleteDataSet(string id)
        {
            try
            {
                var db      = new InlaksBIContext();
                var dataset = db.DataSets.FirstOrDefault(d => d.DataSetName == id.Trim());
                db.DataSets.Remove(dataset);
                db.SaveChanges();

                var warehouse = db.getWarehouse(new Settings().warehousedbtype);

                warehouse.DeleteDataSet(id);

                return("0");
            }
            catch (Exception s)
            {
                return("1");
            }
        }
Example #7
0
        public ActionResult ProcessPassword(PasswordChange change)
        {
            var message    = "";
            var errorclass = "green";
            var context    = new InlaksBIContext();

            try
            {
                if (change.Password == change.NewPassword)
                {
                    goto End;
                }

                var user    = (User)Session["User"];
                var hasher  = new BasicHash();
                var olduser = context.Users.FirstOrDefault(u => u.UserID == user.UserID);
                if (!hasher.VerifyHashedPassword(olduser.Password, change.Password))
                {
                    message    = "Current Password is Invalid";
                    errorclass = "red";
                }
                else
                {
                    olduser.Password   = new BasicHash().HashPassword(change.NewPassword);
                    olduser.RePassword = olduser.Password;
                    context.SaveChanges();
                    message    = "Password Changed Sucessfully";
                    errorclass = "green";
                }

                End :;
            }
            catch (Exception e)
            {
                message    = "Failed to effect password change. Please seek technical assistance";
                errorclass = "red";
            }
            ViewBag.message    = message;
            ViewBag.errorclass = errorclass;
            return(View("ChangePassword", new PasswordChange()));
        }
Example #8
0
        public string SaveUserReportState()
        {
            try
            {
                //  var profittable = getProfitabilityTable(0);
                var db = new InlaksBIContext();

                var pivotconfig = Request.Form["pivotconfig"];
                var reportid    = Request.Form["reportid"].toInt();
                var InstanceID  = Request.Form["InstanceID"];
                var user        = (User)Session["User"];

                var prevstate = db.UserReportStates.FirstOrDefault(r => r.ReportID == reportid && r.User.UserID == user.UserID);

                var state = prevstate.isNull() ? db.UserReportStates.Create() : prevstate;

                state.InstanceID = InstanceID;
                state.ConfigData = pivotconfig;
                state.ReportID   = reportid;
                state.User       = db.Users.FirstOrDefault(u => u.UserID == user.UserID);

                if (prevstate == null)
                {
                    db.UserReportStates.Add(state);
                }


                db.SaveChanges();



                return("Report State Saved Successfully");
            }
            catch (Exception d)
            {
                return("Error encountered while saving state. Please contact Admin");
            }
        }
Example #9
0
        public ActionResult ProcessAuth(AuthSetup auth)
        {
            try
            {
                var db      = new InlaksBIContext();
                var oldauth = db.AuthConfig.First();

                oldauth.AuthType = auth.AuthType;
                oldauth.Server   = auth.Server;
                db.SaveChanges();

                ViewBag.message    = auth.AuthType + " Authentication Mode Activated Successfully";
                ViewBag.errorclass = "green";
            }
            catch (Exception e)
            {
                ViewBag.message    = "Failed to apply changes, please seek technical assistance";
                ViewBag.errorclass = "red";
            }



            return(View("AuthSetup", auth));
        }
Example #10
0
        public string CreateDataSet()
        {
            try
            {
                var data = Request.Form["datasetdata"];

                var moduleid = Request.Form["module"].toInt();

                var datasetobject = JsonConvert.DeserializeObject <List <DatasetObject> >(data);

                bool isduplicateTable = datasetobject.GroupBy(d => d.TableName).Count() < datasetobject.Count;

                if (isduplicateTable)
                {
                    return("1");
                }

                StringBuilder sb  = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();

                int tcounter = 0;

                int ccounter = 0;

                string[] tags = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

                foreach (DatasetObject tbitem in datasetobject)
                {
                    if (tcounter == 0)    //handling the first table
                    {
                        sb2.Append(" from \"" + tbitem.TableName + "\" " + tags[0]);
                    }
                    else
                    {
                        var pretag   = tags[tcounter - 1];     //setting previous table values
                        var pretable = datasetobject[tcounter - 1];
                        sb2.Append(" inner join \"" + tbitem.TableName + "\" " + tags[tcounter] + " on (" + pretag + ".\"" + pretable.NxtTable + "\"=" + tags[tcounter] + ".\"" + tbitem.PreTable + "\") ");
                    }

                    ccounter = 0;

                    if (tbitem.Columns.isNull())
                    {
                        sb.Append(tags[tcounter] + ".*");
                    }
                    else
                    {
                        foreach (string column in tbitem.Columns)
                        {
                            ccounter++;

                            sb.Append(tags[tcounter] + ".\"" + column + "\"");

                            if (ccounter < tbitem.Columns.Length)
                            {
                                sb.Append(",");
                            }
                        }
                    }
                    tcounter++;

                    if (tcounter < datasetobject.Count)
                    {
                        sb.Append(",");
                    }
                }

                string cols = sb.ToString();


                string tabs = sb2.ToString();

                var db = new InlaksBIContext();

                var script = "CREATE MATERIALIZED VIEW public." + datasetobject[0].DataSetName + " AS   Select ";

                var dataset = new DataSetDetail();

                dataset.Script = script + cols + tabs;

                dataset.DataSetName = datasetobject[0].DataSetName;


                DBInterface dbinterface = new PostgreSQLDBInterface(new Settings().warehousedb);

                int resp = dbinterface.Execute(dataset.Script);

                var sql = "select * from \"" + dataset.DataSetName + "\" LIMIT 1";

                var dt = dbinterface.getData(sql);


                dataset.Module = db.Modules.Where(m => m.ModuleID == moduleid).FirstOrDefault();

                db.DataSets.Add(dataset);

                db.SaveChanges();

                if (dt.Rows.Count > 0)
                {
                    return("0");
                }

                else
                {
                    return("DataSet Created sucessfully but has no data");
                }
            }


            catch (Exception e)
            {
                return(e.Message);
            }
        }
Example #11
0
        public ActionResult ProcessRoleResources()
        {
            var currole = Request.Form["role"];

            if (currole == null)
            {
                ViewBag.Message = "A role must be selected";

                ViewBag.errorclass = "red";

                return(View("RolesResources"));
            }

            try
            {
                var resources = Request.Form["resources"];

                var roleid = int.Parse(currole);

                var db = new InlaksBIContext();

                var previous = db.RolesResources.Where(r => r.Role.RoleID == roleid).ToList();

                db.RolesResources.RemoveRange(previous);

                if (resources != null)
                {
                    foreach (string rid in resources.Split(','))
                    {
                        var resourceid = int.Parse(rid);

                        var role     = db.Roles.FirstOrDefault(r => r.RoleID == roleid);
                        var resource = db.Resources.FirstOrDefault(r => r.ResourceID == resourceid);

                        var rolesresource = new RoleResource()
                        {
                            Resource = resource, Role = role
                        };

                        db.RolesResources.Add(rolesresource);
                    }
                }


                ViewBag.Message = "Resource(s) Assigned Successfully";

                ViewBag.errorclass = "green";

                db.SaveChanges();
            }
            catch (Exception e)
            {
                ViewBag.Message = "Failed to Assign Resource(s); Please seek technical assistance";

                ViewBag.errorclass = "red";
            }



            return(View("RolesResources"));
        }
Example #12
0
        public ActionResult ProcessUser(User user, string id, string mode)
        {
            var message    = "";
            var errorclass = "green";
            var context    = new InlaksBIContext();

            switch (mode)
            {
            case "create":
                try
                {
                    var role = context.Roles.FirstOrDefault(r => r.RoleID == user.RoleID);

                    IPasswordHasher hash = new BasicHash();

                    user.Password   = hash.HashPassword(user.Password);
                    user.RePassword = (user.Password);
                    user.UserRole   = role;

                    context.Users.Add(user);

                    context.SaveChanges();

                    message = "User Created Successfully";
                }
                catch (Exception e)
                {
                    message    = "Failed to create user. Please seek technical assistance";
                    errorclass = "red";
                }
                break;

            case "edit":
                ViewBag.mode = "edit";
                try
                {
                    var role = context.Roles.FirstOrDefault(r => r.RoleID == user.RoleID);

                    var olduser = context.Users.FirstOrDefault(u => u.UserID == id);



                    olduser.UserRole   = role;
                    olduser.Name       = user.Name;
                    olduser.Email      = user.Email;
                    olduser.RePassword = olduser.Password;

                    olduser.UserRole = role;


                    context.SaveChanges();

                    message = "User Modified Successfully";
                }
                catch (Exception e)
                {
                    message    = "Failed to Modify user. Please seek technical assistance";
                    errorclass = "red";
                }
                break;
            }


            return(View("CreateUser", new User()
            {
                errorclass = errorclass, Message = message
            }));
        }