Пример #1
0
        public ActionResult Create([Bind(Include = "Id,AdminLoginIp,Email,MailPassword")] SafetyModel safetyModel)
        {
            if (ModelState.IsValid)
            {
                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "SafetyModel";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(safetyModel);
                logingInfoModel.SysDate      = DateTime.Now;
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential

                db.SafetyModels.Add(safetyModel);
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }

            return(View(safetyModel));
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            RoleMenuMapping roleMenuMapping = db.RoleMenuMappings.Find(id);

            // Saving Longing Credential
            LoginInfoModel logingInfoModel = new LoginInfoModel();
            PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);

            logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
            if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
            {
                return(RedirectToAction("Login", "Account"));
            }
            logingInfoModel.UsedModel    = "RoleMenuMapping";
            logingInfoModel.TypeOfAction = TypeOfAction.Delete;
            logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(roleMenuMapping);
            logingInfoModel.SysDate      = DateTime.Now;
            db.LoginInfoModels.Add(logingInfoModel);
            db.SaveChanges();
            // Saving Longing Credential


            db.RoleMenuMappings.Remove(roleMenuMapping);
            db.SaveChanges();



            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Edit([Bind(Include = "Id,RoleId,RoleIdText,MenuInfoId,MenuInfoIdText,CanView,CanCreate,CanEdit,CanDelete,Active")] RoleMenuMapping roleMenuMapping)
        {
            if (ModelState.IsValid)
            {
                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "RoleMenuMapping";
                logingInfoModel.TypeOfAction = TypeOfAction.Update;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(roleMenuMapping);
                logingInfoModel.SysDate      = DateTime.Now;
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential

                db.Entry(roleMenuMapping).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(roleMenuMapping));
        }
Пример #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            var RoleName = db.RoleMasters.Where(w => w.Id == id).FirstOrDefault().Name;

            var RoleExistedInUser = db.RoleMasters.Where(w => w.Name == RoleName).FirstOrDefault();

            if (RoleName == "Admin" || RoleExistedInUser != null)
            {
                return(RedirectToAction("Index"));
            }

            RoleMaster roleMasterDel = db.RoleMasters.Find(id);

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
            var role        = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();

            role = roleManager.FindByName(roleMasterDel.Name);
            var roleResult = roleManager.DeleteAsync(role);


            using (var db = new ApplicationDbContext())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        RoleMaster roleMaster = db.RoleMasters.Find(id);

                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModel.UsedModel    = "RoleMaster";
                        logingInfoModel.TypeOfAction = TypeOfAction.Delete;
                        logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(roleMaster);
                        logingInfoModel.SysDate      = DateTime.Now;
                        db.LoginInfoModels.Add(logingInfoModel);
                        db.RoleMasters.Remove(roleMaster);

                        if (roleResult.Result.Errors.Count() == 0)
                        {
                            db.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,UserId,Name,RoleId,Active,UserCell")] UserMaster userMaster)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId  = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("UserMasters") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault();

            if (!canEdit)
            {
                return(RedirectToAction("Index"));
            }



            // to ensure same role single user
            var roleAlreadyIn = db.UserMasters.Where(w => w.RoleId == userMaster.RoleId).FirstOrDefault();

            if (roleAlreadyIn != null)
            {
                return(RedirectToAction("Index"));
            }

            // to ensure same role single user

            if (ModelState.IsValid)
            {
                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "UserMaster";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.SysDate      = DateTime.Now;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(userMaster);

                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential


                db.UserMasters.Add(userMaster);
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }

            ViewBag.RoleId = new SelectList(db.RoleMasters, "Id", "Name", userMaster.RoleId);
            return(View(userMaster));
        }
Пример #6
0
        public ActionResult Create([Bind(Include = "Id,Name,Active")] RoleMaster roleMaster, string DepartmentName)
        {
            roleMaster.Name = roleMaster.Name + " " + DepartmentName;

            if (db.RoleMasters.Where(w => w.Name == roleMaster.Name).ToList().Count() > 0)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                db.RoleMasters.Add(roleMaster);
                db.SaveChanges();

                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(db));
                var role        = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = roleMaster.Name;
                roleManager.Create(role);


                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }

                logingInfoModel.UsedModel    = "RoleMaster";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(role);
                logingInfoModel.SysDate      = DateTime.Now;

                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential

                return(RedirectToAction("Index"));
            }

            List <SelectListItem> DepartmentNameList = new List <SelectListItem>();

            foreach (var Depart in db.Departments.ToList())
            {
                DepartmentNameList.Add(new SelectListItem()
                {
                    Text = Depart.DepartmentName.ToString(), Value = Depart.DepartmentName.ToString()
                });
            }
            ViewBag.DepartmentNameData = new SelectList(DepartmentNameList.Distinct(), "Value", "Text");

            return(View(roleMaster));
        }
        public ActionResult Create([Bind(Include = "Id,Depart,Role,UpperRole")] Organogram organogram)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId    = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault();


            var upperNotExisted = db.Organograms.Where(w => w.Role == organogram.UpperRole).FirstOrDefault();


            if (!canCreate || upperNotExisted == null || db.Organograms.Where(w => w.Role == organogram.Role).Count() > 0)
            {
                return(RedirectToAction("Index"));
            }



            if (ModelState.IsValid)
            {
                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "Organogram";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(organogram);
                logingInfoModel.SysDate      = DateTime.Now;
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential


                db.Organograms.Add(organogram);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(organogram));
        }
        public ActionResult Create([Bind(Include = "Id,BankName,BranchName")] BankAndBranch bankAndBranch)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ApplicationDbContext())
                {
                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            context.BankAndBranches.Add(bankAndBranch);
                            // context.SaveChanges();
                            // Saving Longing Credential
                            LoginInfoModel logingInfoModel = new LoginInfoModel();
                            PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                            logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                            if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                            {
                                return(RedirectToAction("Login", "Account"));
                            }
                            logingInfoModel.UsedModel    = "BankAndBranches";
                            logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                            logingInfoModel.SysDate      = DateTime.Now;
                            logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(bankAndBranch);
                            context.LoginInfoModels.Add(logingInfoModel);
                            context.SaveChanges();
                            // Saving Longing Credential
                            dbContextTransaction.Commit();
                            return(RedirectToAction("Index"));
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
            }

            return(View(bankAndBranch));
        }
Пример #9
0
        public ActionResult Edit([Bind(Include = "Id,DepartmentName")] Department department)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId  = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Departments") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault();

            if (!canEdit)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "Department";
                logingInfoModel.TypeOfAction = TypeOfAction.Update;
                logingInfoModel.SysDate      = DateTime.Now;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(department);
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential


                db.Entry(department).State = EntityState.Modified;
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }
            return(View(department));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            using (var context = new ApplicationDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        BankAndBranch bankAndBranch = context.BankAndBranches.Find(id);


                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModel.UsedModel    = "BankAndBranches";
                        logingInfoModel.TypeOfAction = TypeOfAction.Delete;
                        logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(bankAndBranch);
                        logingInfoModel.SysDate      = DateTime.Now;
                        context.LoginInfoModels.Add(logingInfoModel);
                        context.BankAndBranches.Remove(bankAndBranch);
                        // Saving Longing Credential
                        context.SaveChanges();
                        dbContextTransaction.Commit();
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Id,MenuName,MenuURL,MenuParentID,MenuParentIDText,CanView,CanCreate,CanEdit,CanDelete,Active")] MenuInfo menuInfo)
        {
            if (ModelState.IsValid)
            {
                var MenuParent = db.MenuInfoes.Where(w => w.Id == menuInfo.MenuParentID).FirstOrDefault();
                menuInfo.MenuParentIDText = MenuParent.MenuName;

                if (!User.IsInRole("Admin"))
                {
                    return(RedirectToAction("Login", "Home"));
                }


                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel              = populateLoginInfoCredencial.getLoginInfoCredencial();
                logingInfoModel.UsedModel    = "MenuInfo";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(menuInfo);
                logingInfoModel.SysDate      = DateTime.Now;
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential

                db.MenuInfoes.Add(menuInfo);
                db.SaveChanges();



                return(RedirectToAction("Index"));
            }

            return(View(menuInfo));
        }
        public ActionResult Edit([Bind(Include = "Id,Depart,Role,UpperRole")] Organogram organogram)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId  = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canEdit = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanEdit).FirstOrDefault();

            if (!canEdit || db.Organograms.Min(o => o.Id) == organogram.Id || db.Organograms.Where(w => w.Id != organogram.Id && w.Role == organogram.Role).Count() > 0)
            {
                return(RedirectToAction("Index"));
            }


            if (ModelState.IsValid)
            {
                using (var context = new ApplicationDbContext())
                {
                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            var organogramToUpdate = context.Organograms.Where(w => w.Id == organogram.Id).FirstOrDefault();
                            organogramToUpdate.Depart    = organogram.Depart;
                            organogramToUpdate.Role      = organogram.Role;
                            organogramToUpdate.UpperRole = organogram.UpperRole;

                            List <LoginInfoModel> logingInfoModelList = new  List <LoginInfoModel>();
                            // Saving Longing Credential
                            LoginInfoModel logingInfoModel = new LoginInfoModel();
                            PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                            logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                            if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                            {
                                return(RedirectToAction("Login", "Account"));
                            }

                            logingInfoModel.UsedModel    = "Organogram";
                            logingInfoModel.TypeOfAction = TypeOfAction.Update;
                            logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(organogramToUpdate);
                            logingInfoModel.SysDate      = DateTime.Now;
                            logingInfoModelList.Add(logingInfoModel);


                            string PreviousRole = context.Organograms.Where(w => w.Id == organogramToUpdate.Id).FirstOrDefault().Role;

                            foreach (var organogramUpdate in context.Organograms.Where(w => w.UpperRole == PreviousRole).ToList())
                            {
                                organogramUpdate.UpperRole = organogram.Role;

                                LoginInfoModel logingInfoModelOne = new LoginInfoModel();
                                PopulateLoginInfoCredencial populateLoginInfoCredencialOne = new PopulateLoginInfoCredencial(logingInfoModelOne);
                                logingInfoModelOne = populateLoginInfoCredencialOne.getLoginInfoCredencial();
                                if (!populateLoginInfoCredencialOne.ValidateIPv4(logingInfoModelOne.LoginIp))
                                {
                                    return(RedirectToAction("Login", "Account"));
                                }

                                logingInfoModelOne.UsedModel    = "Organogram";
                                logingInfoModelOne.TypeOfAction = TypeOfAction.Update;
                                logingInfoModelOne.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(organogramUpdate);
                                logingInfoModelOne.SysDate      = DateTime.Now;
                                logingInfoModelList.Add(logingInfoModelOne);
                            }
                            context.LoginInfoModels.AddRange(logingInfoModelList);
                            context.Entry(organogramToUpdate).State = EntityState.Modified;
                            context.SaveChanges();
                            dbContextTransaction.Commit();

                            return(RedirectToAction("Index"));
                        }
                        catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex)
                        {
                            dbContextTransaction.Rollback();
                        }
                        catch (System.Data.Entity.Core.EntityCommandCompilationException ex)
                        {
                            dbContextTransaction.Rollback();
                        }
                        catch (System.Data.Entity.Core.UpdateException ex)
                        {
                            dbContextTransaction.Rollback();
                        }

                        catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext
                        {
                            dbContextTransaction.Rollback();
                        }

                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
            }
            return(View(organogram));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var RoleId   = db.UserMasters.Where(w => w.Id == id).FirstOrDefault().RoleId;
            var RoleName = db.RoleMasters.Where(w => w.Id == RoleId).FirstOrDefault().Name;

            if (RoleName == "Admin")
            {
                return(RedirectToAction("Index"));
            }

            var RoleIdInUse = db.RoleMenuMappings.Where(w => w.RoleId == RoleId).FirstOrDefault();

            if (RoleIdInUse != null)
            {
                return(RedirectToAction("Index"));
            }

            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId    = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            CanDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("UserMasters") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault();

            if (!CanDelete)
            {
                return(RedirectToAction("Index"));
            }


            using (var db = new ApplicationDbContext())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        UserMaster userMaster = db.UserMasters.Find(id);

                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModel.UsedModel    = "UserMaster";
                        logingInfoModel.TypeOfAction = TypeOfAction.Delete;
                        var uMaster = new
                        {
                            Id = userMaster.Id
                            ,
                            UserId = userMaster.UserId
                            ,
                            UserCell = userMaster.UserCell
                            ,
                            Name = userMaster.Name
                            ,
                            RoleId = userMaster.RoleId
                            ,
                            Active = userMaster.Active
                        };
                        logingInfoModel.Data    = Newtonsoft.Json.JsonConvert.SerializeObject(uMaster);
                        logingInfoModel.SysDate = DateTime.Now;
                        db.LoginInfoModels.Add(logingInfoModel);
                        db.UserMasters.Remove(userMaster);
                        var UserNameToDel = userMaster.Name;
                        db.SaveChanges();

                        var             manager = new ApplicationUserManager(new UserStore <ApplicationUser>(db));
                        ApplicationUser userDel = manager.FindByName(UserNameToDel);
                        manager.DeleteAsync(userDel);
                        Task.Delay(2000).Wait();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }


            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId    = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canDelete = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("Organograms") && rm.RoleId == roleId select rm.CanDelete).FirstOrDefault();

            if (!canDelete || db.Organograms.Min(o => o.Id) == id)
            {
                return(RedirectToAction("Index"));
            }

            using (var context = new ApplicationDbContext())
            {
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        Organogram organogram = context.Organograms.Find(id);

                        List <LoginInfoModel> logingInfoModelList = new List <LoginInfoModel>();
                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }

                        logingInfoModel.UsedModel    = "Organogram";
                        logingInfoModel.TypeOfAction = TypeOfAction.Delete;
                        logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(organogram);
                        logingInfoModel.SysDate      = DateTime.Now;
                        logingInfoModelList.Add(logingInfoModel);

                        var DeletedRoleEntity = context.Organograms.Where(w => w.Id == organogram.Id).FirstOrDefault();
                        var Role      = DeletedRoleEntity.Role;
                        var UpperRole = DeletedRoleEntity.UpperRole;

                        foreach (var organogramUpdate in context.Organograms.Where(w => w.UpperRole == Role).ToList())
                        {
                            organogramUpdate.UpperRole = UpperRole;
                            LoginInfoModel logingInfoModelOne = new LoginInfoModel();
                            PopulateLoginInfoCredencial populateLoginInfoCredencialOne = new PopulateLoginInfoCredencial(logingInfoModelOne);
                            logingInfoModelOne = populateLoginInfoCredencialOne.getLoginInfoCredencial();
                            if (!populateLoginInfoCredencialOne.ValidateIPv4(logingInfoModelOne.LoginIp))
                            {
                                return(RedirectToAction("Login", "Account"));
                            }

                            logingInfoModelOne.UsedModel    = "Organogram";
                            logingInfoModelOne.TypeOfAction = TypeOfAction.Update;
                            logingInfoModelOne.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(organogramUpdate);
                            logingInfoModelOne.SysDate      = DateTime.Now;
                            logingInfoModelList.Add(logingInfoModelOne);
                        }
                        context.LoginInfoModels.AddRange(logingInfoModelList);
                        context.Organograms.Remove(organogram);
                        context.SaveChanges();
                        dbContextTransaction.Commit();

                        return(RedirectToAction("Index"));
                    }
                    catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                    catch (System.Data.Entity.Core.EntityCommandCompilationException ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                    catch (System.Data.Entity.Core.UpdateException ex)
                    {
                        dbContextTransaction.Rollback();
                    }

                    catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext
                    {
                        dbContextTransaction.Rollback();
                    }

                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }


            Organogram organogramTemp = db.Organograms.Find(id);

            if (organogramTemp == null)
            {
                return(HttpNotFound());
            }
            return(View(organogramTemp));
        }
Пример #15
0
        public ActionResult Create(ArtWork artwork, FormCollection collection, HttpPostedFileBase image)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId    = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("ArtWorks") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault();

            if (!canCreate)
            {
                return(RedirectToAction("Index"));
            }



            using (var db = new ApplicationDbContext())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Clear();

                        string CheckList = collection["Departments"];

                        if (CheckList != null)
                        {
                            string[] vListDepartment = CheckList.Split(',');

                            foreach (var d in vListDepartment)
                            {
                                if (sb.Length > 0)
                                {
                                    sb.Append(" , " + d);
                                }
                                else
                                {
                                    sb.Append(d);
                                }
                            }
                        }



                        if (image != null)
                        {
                            //attach the uploaded image to the object before saving to Database
                            artwork.ImageMimeType = image.ContentLength;
                            artwork.ImageData     = new byte[image.ContentLength];
                            image.InputStream.Read(artwork.ImageData, 0, image.ContentLength);

                            // To Get the Max Id
                            int countAw = db.ArtWorks.Count();
                            int maxId   = 0;
                            if (countAw > 0)
                            {
                                maxId = db.ArtWorks.Max(m => m.Id) + 1;
                            }
                            else
                            {
                                maxId = 1;
                            }

                            string   FileWhole      = image.FileName;
                            string[] SplitFileWhole = FileWhole.Split('\\');

                            int LastPartOfFile = SplitFileWhole.Count() - 1;
                            //Save image to file
                            var filename = maxId.ToString() + "_" + artwork.User + "_" + SplitFileWhole[LastPartOfFile];
                            artwork.FileAddressInfo = filename;

                            var    filePathOriginal      = Server.MapPath("~/Content/Uploads/Originals");
                            var    filePathThumbnail     = Server.MapPath("~/Content/Uploads/Thumbnails");
                            string savedFileName         = Path.Combine(filePathOriginal, filename);
                            string UploadedfileExtension = Path.GetExtension(image.FileName);
                            if (System.IO.File.Exists(savedFileName))
                            {
                                System.IO.File.Delete(savedFileName);
                            }
                            image.SaveAs(savedFileName);

                            // back up into external drive
                            try
                            {
                                var    ExDrive = db.TestCallls.Select(s => s.value).FirstOrDefault();
                                string externalLocationAddress = ExDrive + fileStoreCreateFolderName.getFolderName();

                                bool exists = System.IO.Directory.Exists(externalLocationAddress);
                                if (!exists)
                                {
                                    System.IO.Directory.CreateDirectory(externalLocationAddress);
                                }
                                string externalFileName = Path.Combine(externalLocationAddress, filename);
                                bool   fileExist        = System.IO.File.Exists(externalFileName);
                                if (fileExist)
                                {
                                    Random r = new Random();
                                    // Later to be indetified by the sequence which got start in between 900000 to 900100
                                    string ExistExternalFileName = Path.Combine(externalLocationAddress, r.Next(900000, 900100).ToString() + "_" + filename);
                                    image.SaveAs(ExistExternalFileName);
                                }
                                else
                                {
                                    string ExistExternalFileName = Path.Combine(externalLocationAddress, filename);
                                    image.SaveAs(ExistExternalFileName);
                                }
                            }
                            catch (Exception ex)
                            {
                            }

                            // back up into external drive

                            //Read image back from file and create thumbnail from it
                            var imageFile = Path.Combine(Server.MapPath("~/Content/Uploads/Originals"), filename);



                            if (UploadedfileExtension.ToUpper() == ".JPG" || UploadedfileExtension.ToUpper() == ".JPEG" || UploadedfileExtension.ToUpper() == ".PNG" || UploadedfileExtension.ToUpper() == ".GIF")
                            {
                                using (var srcImage = Image.FromFile(imageFile))
                                    using (var newImage = new Bitmap(100, 100))
                                        using (var graphics = Graphics.FromImage(newImage))
                                            using (var stream = new MemoryStream())
                                            {
                                                graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                                                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                                                graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                                                graphics.DrawImage(srcImage, new Rectangle(0, 0, 100, 100));
                                                newImage.Save(stream, ImageFormat.Png);
                                                var thumbNew = File(stream.ToArray(), "image/png");
                                                artwork.ArtworkThumbnail = thumbNew.FileContents;
                                            }
                            }


                            artwork.CreateTime      = DateTime.Now;
                            artwork.User            = System.Web.HttpContext.Current.User.Identity.Name;
                            artwork.ValidDepartment = sb.ToString();


                            // Saving Longing Credential
                            LoginInfoModel logingInfoModel = new LoginInfoModel();
                            PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                            logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                            if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                            {
                                return(RedirectToAction("Login", "Account"));
                            }
                            logingInfoModel.UsedModel    = "ArtWork";
                            logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                            logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(artwork);
                            logingInfoModel.SysDate      = DateTime.Now;
                            db.LoginInfoModels.Add(logingInfoModel);

                            // Saving Longing Credential


                            //Save model object to database
                            db.ArtWorks.Add(artwork);
                            db.SaveChanges();
                            dbContextTransaction.Commit();
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                    catch (System.Data.Entity.Core.EntityCommandCompilationException ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                    catch (System.Data.Entity.Core.UpdateException ex)
                    {
                        dbContextTransaction.Rollback();
                    }

                    catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext
                    {
                        dbContextTransaction.Rollback();
                    }

                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }



            return(View(artwork));
        }
Пример #16
0
        public ActionResult Create(List <MenuInfo> menuList, string RoleName)
        {
            var roleToDel = 0;

            List <RoleMenuMapping> roleMenuMappings = db.RoleMenuMappings.Where(drm => drm.RoleIdText == RoleName).ToList();

            if (roleMenuMappings != null && roleMenuMappings.Count() > 0)
            {
                roleToDel = roleMenuMappings[0].RoleId;
            }

            foreach (var item in roleMenuMappings)
            {
                db.RoleMenuMappings.Remove(item);
                db.SaveChanges();
            }

            RoleMenuMapping roleMenuMapping = new  RoleMenuMapping();
            var             RoleList        = db.RoleMasters.ToList();
            var             AllMenu         = db.MenuInfoes.ToList();

            if (ModelState.IsValid)
            {
                foreach (var item in menuList)
                {
                    var MenoInfoIdText = AllMenu.Where(am => am.Id == item.Id).Select(s => s.MenuParentIDText).FirstOrDefault();
                    if (MenoInfoIdText == null || MenoInfoIdText == "")
                    {
                        MenoInfoIdText = AllMenu.Where(am => am.Id == item.Id).Select(s => s.MenuName).FirstOrDefault();
                    }
                    var RoleId = RoleList.Where(rl => rl.Name == RoleName).Select(r => r.Id).FirstOrDefault();
                    roleMenuMapping.MenuInfoId     = item.Id;
                    roleMenuMapping.MenuInfoIdText = MenoInfoIdText;
                    roleMenuMapping.CanView        = Convert.ToBoolean(item.CanView);
                    roleMenuMapping.CanCreate      = Convert.ToBoolean(item.CanCreate);
                    roleMenuMapping.CanEdit        = Convert.ToBoolean(item.CanEdit);
                    roleMenuMapping.CanDelete      = Convert.ToBoolean(item.CanDelete);
                    roleMenuMapping.CanClose       = Convert.ToBoolean(item.CanClose);
                    roleMenuMapping.Active         = item.Active;
                    roleMenuMapping.RoleId         = RoleId == 0 ? roleToDel : RoleId;
                    roleMenuMapping.RoleIdText     = RoleName;
                    db.RoleMenuMappings.Add(roleMenuMapping);


                    // Saving Longing Credential
                    LoginInfoModel logingInfoModel = new LoginInfoModel();
                    PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                    logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                    if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                    {
                        return(RedirectToAction("Login", "Account"));
                    }
                    logingInfoModel.UsedModel    = "RoleMenuMapping";
                    logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                    logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(roleMenuMapping);
                    logingInfoModel.SysDate      = DateTime.Now;
                    db.LoginInfoModels.Add(logingInfoModel);
                    db.SaveChanges();
                    // Saving Longing Credential


                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(roleMenuMapping));
        }
        public ActionResult UserUpdate(string ShowUserId, string ShowEmail, bool ShowActive, bool ShowPasswordReset, string UserCell)
        {
            if (string.IsNullOrEmpty(ShowEmail))
            {
                foreach (char singleChar in ShowUserId)
                {
                    if (Char.IsLetter(singleChar))
                    {
                        ShowEmail += singleChar.ToString();
                    }
                }

                Random r = new Random();

                ShowEmail = ShowEmail + "_" + r.Next(10000, 100000).ToString() + "@silverglobalfashion.com";
            }


            string newPassword = "";

            if (ShowPasswordReset)
            {
                newPassword = "******";
            }


            using (var db = new ApplicationDbContext())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        UserMaster      userMaster = db.UserMasters.Where(w => w.Name == ShowUserId).FirstOrDefault();
                        ApplicationUser appUser    = db.Users.Where(w => w.UserName == ShowUserId).FirstOrDefault();

                        if (!string.IsNullOrEmpty(ShowEmail))
                        {
                            appUser.Email = ShowEmail;
                        }

                        if (!string.IsNullOrEmpty(UserCell))
                        {
                            userMaster.UserCell = UserCell;
                        }

                        if (ShowPasswordReset)
                        {
                            appUser.PasswordHash = newPassword;
                        }

                        userMaster.Active = ShowActive;


                        UserMaster logUserMaster = new UserMaster();
                        logUserMaster.Active   = userMaster.Active;
                        logUserMaster.Id       = userMaster.Id;
                        logUserMaster.Name     = userMaster.Name;
                        logUserMaster.RoleId   = userMaster.RoleId;
                        logUserMaster.UserId   = userMaster.UserId;
                        logUserMaster.UserCell = userMaster.UserCell;



                        // Saving Longing Credential
                        LoginInfoModel logingInfoModel = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                        logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModel.UsedModel    = "UserMaster";
                        logingInfoModel.TypeOfAction = TypeOfAction.Update;
                        logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(logUserMaster);
                        logingInfoModel.SysDate      = DateTime.Now;
                        db.LoginInfoModels.Add(logingInfoModel);


                        LoginInfoModel logingInfoModelOne = new LoginInfoModel();
                        PopulateLoginInfoCredencial populateLoginInfoCredencialOne = new PopulateLoginInfoCredencial(logingInfoModelOne);
                        logingInfoModelOne = populateLoginInfoCredencialOne.getLoginInfoCredencial();
                        if (!populateLoginInfoCredencialOne.ValidateIPv4(logingInfoModelOne.LoginIp))
                        {
                            return(RedirectToAction("Login", "Account"));
                        }
                        logingInfoModelOne.UsedModel    = "ApplicationUser";
                        logingInfoModelOne.TypeOfAction = TypeOfAction.Update;
                        logingInfoModelOne.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(appUser);
                        logingInfoModelOne.SysDate      = DateTime.Now;
                        db.LoginInfoModels.Add(logingInfoModelOne);

                        db.Entry(userMaster).State = EntityState.Modified;
                        db.Entry(appUser).State    = EntityState.Modified;

                        db.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }



            return(RedirectToAction("Index"));
        }
        public ActionResult Create(RoleBasedSignature roleBasedSignature, FormCollection collection, HttpPostedFileBase image)
        {
            MembershipHelp mHelp = new MembershipHelp(); var role = mHelp.logingUserRole(User.Identity.Name);
            var            roleId    = db.RoleMasters.Where(w => w.Name == role).Select(s => s.Id).FirstOrDefault();
            var            canCreate = (from m in db.MenuInfoes join rm in db.RoleMenuMappings on m.Id equals rm.MenuInfoId where m.MenuURL.Contains("RoleBasedSignatures") && rm.RoleId == roleId select rm.CanCreate).FirstOrDefault();

            if (!canCreate)
            {
                return(RedirectToAction("Index"));
            }


            var roleBasedSignatueUpdate = db.RoleBasedSignatures.Where(w => w.RoleName == roleBasedSignature.RoleName).ToList();

            foreach (var rbsu in roleBasedSignatueUpdate)
            {
                rbsu.IsAcive         = false;
                db.Entry(rbsu).State = EntityState.Modified;
                db.SaveChanges();
            }



            if (image != null)
            {
                //attach the uploaded image to the object before saving to Database
                roleBasedSignature.SignatureMimeType = image.ContentLength;
                roleBasedSignature.SignatureData     = new byte[image.ContentLength];
                image.InputStream.Read(roleBasedSignature.SignatureData, 0, image.ContentLength);

                // To Get the Max Id
                int countrbs = db.RoleBasedSignatures.Count();
                int maxId    = 0;
                if (countrbs > 0)
                {
                    maxId = db.RoleBasedSignatures.Max(m => m.Id) + 1;
                }
                else
                {
                    maxId = 1;
                }

                string   FileWhole      = image.FileName;
                string[] SplitFileWhole = FileWhole.Split('\\');

                int LastPartOfFile = SplitFileWhole.Count() - 1;
                //Save image to file
                var filename = maxId.ToString() + "_" + roleBasedSignature.RoleName + "_" + SplitFileWhole[LastPartOfFile];
                roleBasedSignature.FileAddressInfo = filename;

                var    filePathOriginal      = Server.MapPath("~/Content/Uploads/Originals");
                var    filePathThumbnail     = Server.MapPath("~/Content/Uploads/Thumbnails");
                string savedFileName         = Path.Combine(filePathOriginal, filename);
                string UploadedfileExtension = Path.GetExtension(image.FileName);
                if (System.IO.File.Exists(savedFileName))
                {
                    System.IO.File.Delete(savedFileName);
                }
                image.SaveAs(savedFileName);

                // back up into external drive
                try
                {
                    var    ExDrive = db.TestCallls.Select(s => s.value).FirstOrDefault();
                    string externalLocationAddress = ExDrive + fileStoreCreateFolderName.getFolderName();

                    bool exists = System.IO.Directory.Exists(externalLocationAddress);
                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(externalLocationAddress);
                    }
                    string externalFileName = Path.Combine(externalLocationAddress, filename);
                    bool   fileExist        = System.IO.File.Exists(externalFileName);
                    if (fileExist)
                    {
                        Random r = new Random();
                        // Later to be indetified by the sequence which got start in between 900000 to 900100
                        string ExistExternalFileName = Path.Combine(externalLocationAddress, r.Next(900000, 900100).ToString() + "_" + filename);
                        image.SaveAs(ExistExternalFileName);
                    }
                    else
                    {
                        string ExistExternalFileName = Path.Combine(externalLocationAddress, filename);
                        image.SaveAs(ExistExternalFileName);
                    }
                }
                catch (Exception ex)
                {
                }
                // back up into external drive


                roleBasedSignature.CreateTime = DateTime.Now;



                // Saving Longing Credential
                LoginInfoModel logingInfoModel = new LoginInfoModel();
                PopulateLoginInfoCredencial populateLoginInfoCredencial = new PopulateLoginInfoCredencial(logingInfoModel);
                logingInfoModel = populateLoginInfoCredencial.getLoginInfoCredencial();
                if (!populateLoginInfoCredencial.ValidateIPv4(logingInfoModel.LoginIp))
                {
                    return(RedirectToAction("Login", "Account"));
                }
                logingInfoModel.UsedModel    = "RoleBasedSignature";
                logingInfoModel.TypeOfAction = TypeOfAction.Insert;
                logingInfoModel.Data         = Newtonsoft.Json.JsonConvert.SerializeObject(roleBasedSignature);
                logingInfoModel.SysDate      = DateTime.Now;
                db.LoginInfoModels.Add(logingInfoModel);
                db.SaveChanges();
                // Saving Longing Credential
                //Save model object to database
                db.RoleBasedSignatures.Add(roleBasedSignature);
                db.SaveChanges();


                return(RedirectToAction("Index"));
            }
            return(View(roleBasedSignature));
        }