Exemplo n.º 1
0
        private void CreateHostRoleAndUsers()
        {
            //Admin role for host

            var adminRoleForHost = _context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin);

            if (adminRoleForHost == null)
            {
                adminRoleForHost = _context.Roles.Add(new Role {
                    Name = StaticRoleNames.Host.Admin, DisplayName = StaticRoleNames.Host.Admin, IsStatic = true
                });
                _context.SaveChanges();

                //Grant all tenant permissions
                var permissions = PermissionFinder
                                  .GetAllPermissions(new EMSAuthorizationProvider())
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    _context.Permissions.Add(
                        new RolePermissionSetting
                    {
                        Name      = permission.Name,
                        IsGranted = true,
                        RoleId    = adminRoleForHost.Id
                    });
                }

                _context.SaveChanges();
            }

            //Admin user for tenancy host

            var adminUserForHost = _context.Users.FirstOrDefault(u => u.TenantId == null && u.UserName == User.AdminUserName);

            if (adminUserForHost == null)
            {
                adminUserForHost = _context.Users.Add(
                    new User
                {
                    UserName         = User.AdminUserName,
                    Name             = "System",
                    Surname          = "Administrator",
                    EmailAddress     = "*****@*****.**",
                    IsEmailConfirmed = true,
                    Password         = new PasswordHasher().HashPassword(User.DefaultPassword)
                });

                _context.SaveChanges();

                _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id));

                _context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public ActionResult SaveSkill([Bind(Include = "Id,SkillName,Description")] Skill skill)
        {
            if (ModelState.IsValid)
            {
                db.Skills.Add(skill);
                db.SaveChanges();
                return(RedirectToAction("ViewSkill"));
            }

            return(View(skill));
        }
Exemplo n.º 3
0
        public ActionResult SaveEducation(Education education)
        {
            if (ModelState.IsValid)
            {
                db.Educations.Add(education);
                db.SaveChanges();
                return(RedirectToAction("ViewEducation"));
            }

            return(View(education));
        }
Exemplo n.º 4
0
        public ActionResult SaveDesignation(Designation designation)
        {
            if (ModelState.IsValid)
            {
                db.Designations.Add(designation);
                db.SaveChanges();
                return(RedirectToAction("ViewDesignation"));
            }

            return(View(designation));
        }
Exemplo n.º 5
0
        public ActionResult SaveLanguage(Language language)
        {
            if (ModelState.IsValid)
            {
                db.Languages.Add(language);
                db.SaveChanges();
                return(RedirectToAction("ViewLanguage"));
            }

            return(View(language));
        }
Exemplo n.º 6
0
        public ActionResult SaveDepartment(Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("ViewAllDepartment"));
            }

            return(View(department));
        }
Exemplo n.º 7
0
        public ActionResult SaveCertification(Certification certification)
        {
            if (ModelState.IsValid)
            {
                db.Certifications.Add(certification);
                db.SaveChanges();
                ViewBag.Message = "Successfully saved";
            }

            return(View(certification));
        }
Exemplo n.º 8
0
        public ActionResult SaveDivision([Bind(Include = "Id,CountryId,DivisionCode,DivisionName")] Division division)
        {
            if (ModelState.IsValid)
            {
                db.Divisions.Add(division);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryId = new SelectList(db.Countries, "Id", "CountryName", division.CountryId);
            return(View(division));
        }
Exemplo n.º 9
0
        public ActionResult SaveDistrict([Bind(Include = "Id,DivisionId,DistrictCode,DistrictName")] District district)
        {
            if (ModelState.IsValid)
            {
                db.Districts.Add(district);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DivisionId = new SelectList(db.Divisions, "Id", "DivisionName", district.DivisionId);
            return(View(district));
        }
Exemplo n.º 10
0
        public ActionResult SavePoliceStation([Bind(Include = "Id,DistrictId,PoliceStationCode,PoliceStationName")] PoliceStation policestation)
        {
            if (ModelState.IsValid)
            {
                db.PoliceStations.Add(policestation);
                db.SaveChanges();
                return(RedirectToAction("ViewAllPoliceSation"));
            }

            ViewBag.DistrictId = new SelectList(db.Districts, "Id", "DistrictName", policestation.DistrictId);
            return(View(policestation));
        }
        public ActionResult SaveTrainingHistory([Bind(Include = "Id,EmployeeId,TrainingTitle,TrainingTopic,TrainingInstitute,IstituteLocation,InstituteCountry,TrainingYear,TrainingDuration")] EmployeeTrainingHistory employeetraininghistory)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeTrainingHistories.Add(employeetraininghistory);
                db.SaveChanges();
                return(RedirectToAction("ViewTrainingHistory"));
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeetraininghistory.EmployeeId);
            return(View(employeetraininghistory));
        }
Exemplo n.º 12
0
        public ActionResult SaveUnion([Bind(Include = "Id,PoliceStationId,UnionCode,UnionName")] Union union)
        {
            if (ModelState.IsValid)
            {
                db.Unions.Add(union);
                db.SaveChanges();
                return(RedirectToAction("ViewAllUnion"));
            }

            ViewBag.PoliceStationId = new SelectList(db.PoliceStations, "Id", "PoliceStationName", union.PoliceStationId);
            return(View(union));
        }
 public ActionResult SaveEmployeeCertification([Bind(Include = "Id,EmployeeId,CertificationId,InstituteName,FromDate,ToDate")] EmployeeCertification employeecertification)
 {
     if (ModelState.IsValid)
     {
         db.EmployeeCertifications.Add(employeecertification);
         db.SaveChanges();
         return(RedirectToAction("ViewEmployeeCertification"));
     }
     ViewBag.EmployeeId      = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeecertification.EmployeeId);
     ViewBag.CertificationId = new SelectList(db.Certifications, "Id", "CertificationName", employeecertification.CertificationId);
     return(View(employeecertification));
 }
Exemplo n.º 14
0
        public ActionResult SaveExam(Exam exam)
        {
            if (ModelState.IsValid)
            {
                db.Exams.Add(exam);
                db.SaveChanges();
                return(RedirectToAction("ViewExam"));
            }

            ViewBag.EducationId = new SelectList(db.Educations, "Id", "EducationName", exam.EducationId);
            return(View(exam));
        }
Exemplo n.º 15
0
        private void CreateRolesAndUsers()
        {
            //Admin role

            var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin);

            if (adminRole == null)
            {
                adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin)
                {
                    IsStatic = true
                });
                _context.SaveChanges();

                //Grant all permissions to admin role
                var permissions = PermissionFinder
                                  .GetAllPermissions(new EMSAuthorizationProvider())
                                  .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant))
                                  .ToList();

                foreach (var permission in permissions)
                {
                    _context.Permissions.Add(
                        new RolePermissionSetting
                    {
                        TenantId  = _tenantId,
                        Name      = permission.Name,
                        IsGranted = true,
                        RoleId    = adminRole.Id
                    });
                }

                _context.SaveChanges();
            }

            //admin user

            var adminUser = _context.Users.FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == User.AdminUserName);

            if (adminUser == null)
            {
                adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**", User.DefaultPassword);
                adminUser.IsEmailConfirmed = true;
                adminUser.IsActive         = true;

                _context.Users.Add(adminUser);
                _context.SaveChanges();

                //Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public ActionResult SaveEmployeeLanguage([Bind(Include = "Id,EmployeeId,LanguageId,Reading,Speaking,Writing,Understanding")] EmployeeLanguage employeelanguage)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeLanguages.Add(employeelanguage);
                db.SaveChanges();
                return(RedirectToAction("ViewEmployeeLanguage"));
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeelanguage.EmployeeId);
            ViewBag.LanguageId = new SelectList(db.Languages, "Id", "LanguageName", employeelanguage.LanguageId);
            return(View(employeelanguage));
        }
Exemplo n.º 17
0
        public ActionResult SaveEmployeeSkill([Bind(Include = "Id,EmployeeId,SkillId,Details")] EmployeeSkill employeeskill)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeSkills.Add(employeeskill);
                db.SaveChanges();
                return(RedirectToAction("ViewEmployeeSkill"));
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeeskill.EmployeeId);
            ViewBag.SkillId    = new SelectList(db.Skills, "Id", "SkillName", employeeskill.SkillId);
            return(View(employeeskill));
        }
Exemplo n.º 18
0
 public ActionResult SaveDocumentType(DocumentType documentType)
 {
     if (ModelState.IsValid)
     {
         db.DocumentTypes.Add(documentType);
         db.SaveChanges();
         documentType.TypeName    = String.Empty;
         documentType.Description = String.Empty;
         ViewBag.Message          = "Documents type Successfully Saved";
     }
     ModelState.Clear();
     return(View(documentType));
 }
Exemplo n.º 19
0
        public ActionResult SaveEmployeeEducation([Bind(Include = "Id,EmployeeId,EducationId,ExamId,Subject,InstituteName,FromDate,ToDate,Duration,PassingYear")] EmployeEducation employeeducation)
        {
            if (ModelState.IsValid)
            {
                db.EmployeEducations.Add(employeeducation);
                db.SaveChanges();
                return(RedirectToAction("ViewEmployeeEducation"));
            }

            ViewBag.EducationId = new SelectList(db.Educations, "Id", "EducationName", employeeducation.EducationId);
            ViewBag.EmployeeId  = new SelectList(db.Employees, "Id", "EmployeeName", employeeducation.EmployeeId);
            ViewBag.ExamId      = new SelectList(db.Exams, "Id", "ExamName", employeeducation.ExamId);
            return(View(employeeducation));
        }
        public ActionResult SaveEmploymentHistory([Bind(Include = "Id,EmployeeId,CompanyName,CompanyLocation,DepartmentId,DesignationId,EmploymentFromDate,IsCurrentEmployee,EmploymentToDate,Responsibilities")] EmploymentHistory employmenthistory)
        {
            if (ModelState.IsValid)
            {
                db.EmploymentHistories.Add(employmenthistory);
                db.SaveChanges();
                return(RedirectToAction("ViewEmploymentHistory"));
            }

            ViewBag.DepartmentId  = new SelectList(db.Departments, "Id", "DepartmentCode", employmenthistory.DepartmentId);
            ViewBag.DesignationId = new SelectList(db.Designations, "Id", "DesignationCode", employmenthistory.DesignationId);
            ViewBag.EmployeeId    = new SelectList(db.Employees, "Id", "EmployeeRegNo", employmenthistory.EmployeeId);
            return(View(employmenthistory));
        }
Exemplo n.º 21
0
        private void CreateEditions()
        {
            var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName);

            if (defaultEdition == null)
            {
                defaultEdition = new Edition {
                    Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName
                };
                _context.Editions.Add(defaultEdition);
                _context.SaveChanges();

                /* Add desired features to the standard edition, if wanted... */
            }
        }
Exemplo n.º 22
0
 public ActionResult EditEmployeeDocuments(EmployeeDocument employeedocument, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             string fileName  = Path.GetFileNameWithoutExtension(file.FileName);
             string extension = Path.GetExtension(file.FileName);
             fileName = fileName + DateTime.Now.ToString("yymmdd") + extension;
             employeedocument.FilePath = "~/Image/" + fileName;
             fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
             file.SaveAs(Path.Combine(fileName));
             employeedocument.FilePath = fileName;
         }
         using (EMSDbContext dc = new EMSDbContext())
         {
             dc.Entry(employeedocument).State = EntityState.Modified;
             dc.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.FileStatus = "File edit successfully.";
     }
     ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "Id", "TypeName", employeedocument.DocumentTypeId);
     ViewBag.EmployeeId     = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeedocument.EmployeeId);
     return(View(employeedocument));
 }
Exemplo n.º 23
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeDocument employeedocument = db.EmployeeDocuments.Find(id);

            db.EmployeeDocuments.Remove(employeedocument);
            db.SaveChanges();
            return(RedirectToAction("ViewEmployeeDocuments"));
        }
Exemplo n.º 24
0
 public ActionResult SaveCountry(Country country)
 {
     if (ModelState.IsValid)
     {
         if (country.Id != 0)
         {
             db.Entry(country).State = EntityState.Modified;
         }
         else
         {
             db.Countries.Add(country);
         }
         db.SaveChanges();
         return(RedirectToAction("SaveCountry"));
     }
     return(View(country));
 }
Exemplo n.º 25
0
        public void Create()
        {
            new DefaultEditionCreator(_context).Create();
            new DefaultLanguagesCreator(_context).Create();
            new HostRoleAndUserCreator(_context).Create();
            new DefaultSettingsCreator(_context).Create();

            _context.SaveChanges();
        }
Exemplo n.º 26
0
        public JsonResult Delete(int?id)
        {
            EMSDbContext db      = new EMSDbContext();
            Country      country = db.Countries.Find(id);

            db.Countries.Remove(country);
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 27
0
        private void AddSettingIfNotExists(string name, string value, int?tenantId = null)
        {
            if (_context.Settings.IgnoreQueryFilters().Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null))
            {
                return;
            }

            _context.Settings.Add(new Setting(tenantId, null, name, value));
            _context.SaveChanges();
        }
Exemplo n.º 28
0
        public ActionResult SaveEmployee(Employee employee)
        {
            if (ModelState.IsValid)
            {
                employee.EmployeeRegNo = GetEmployeeRegNo(employee);
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("ViewEmployee"));
            }

            ViewBag.CountryId       = new SelectList(db.Countries, "Id", "CountryCode", employee.CountryId);
            ViewBag.DepartmentId    = new SelectList(db.Departments, "Id", "DepartmentCode", employee.DepartmentId);
            ViewBag.DesignationId   = new SelectList(db.Designations, "Id", "DesignationCode", employee.DesignationId);
            ViewBag.DistrictId      = new SelectList(db.Districts, "Id", "DistrictCode", employee.DistrictId);
            ViewBag.DivisionId      = new SelectList(db.Divisions, "Id", "DivisionCode", employee.DivisionId);
            ViewBag.PoliceStationId = new SelectList(db.PoliceStations, "Id", "PoliceStationCode", employee.PoliceStationId);
            ViewBag.UnionId         = new SelectList(db.Unions, "Id", "UnionCode", employee.UnionId);
            return(View(employee));
        }
Exemplo n.º 29
0
        private void AddLanguageIfNotExists(ApplicationLanguage language)
        {
            if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name))
            {
                return;
            }

            _context.Languages.Add(language);
            _context.SaveChanges();
        }
Exemplo n.º 30
0
 public ActionResult SaveAttendance(Attendance attendance)
 {
     if (ModelState.IsValid)
     {
         db.Attendances.Add(attendance);
         db.SaveChanges();
         return(RedirectToAction("ViewAttendance"));
     }
     ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", attendance.EmployeeId);
     return(View());
 }