Пример #1
0
 public string AddOrganizations(string token, Organization objOrganization)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (StudentContext db = new StudentContext())
             {
                 objOrganization.CreatedDate = DateTime.Now;
                 objOrganization.CreatedBy = _userStatistics.UserId;
                 RegistrationToken objToken = new RegistrationToken();
                 objToken.Token = UserStatistics.GenerateToken();
                 objToken.RoleId = (int)UserRoles.OrganizationAdmin;
                 objToken.CreatedBy = _userStatistics.UserId;
                 if (objRep.CreateOrganization(objOrganization, objToken))
                 {
                     //objRep.CreateRegistrationToken(objToken);
                     SaveFiles(token, this.GetType().Name, objOrganization.OrganizationId);
                     EmailHandler.Utilities.SendRegistationEmail(objToken.Token, objOrganization.Email);
                     return Convert.ToString(true);
                 }
                 return Convert.ToString(false);
             }
         }
         return Convert.ToString(false);
     }
     catch (Exception ex)
     {
         return ex.Message.ToString();
     }
 }
Пример #2
0
 public ActionResult RegisterUserStep2(string id = "")
 {
     ViewBag.Error = false;
     RegistrationToken objToken = new RegistrationToken();
     objToken.Token = id;
     return View(objToken);
 }
Пример #3
0
 public ActionResult CreateToken()
 {
     RegistrationToken objToken = new RegistrationToken();
     LoadSelectLists(ref objToken);
     objToken.OrganizationId = ViewBag.OrganizationId == null ? 0 : (int)ViewBag.OrganizationId;
     return View(objToken);
 }
Пример #4
0
 public ActionResult RegisterUserStep2(RegistrationToken objToken)
 {
     ViewBag.Error = false;
     RegistrationToken token = repository.GetRegistrationCode(objToken.Token);
     if (token != null && token.InsertedOn.AddDays(7) > DateTime.Now)
     {
         return RedirectToAction("RegisterUserStep3", new { token.Token });
     }
     ViewBag.Error = true;
     return View();
 }
Пример #5
0
 public ActionResult Create(RegistrationToken token)
 {
     try
     {
         if (ModelState.IsValid)
         {
             token.Token = UserStatistics.GenerateToken();
             token.CreatedBy = _userStatistics.UserId;
             if (repository.CreateToken(token) > 0)
             {
                 ViewBag.Token = token.Token;
                 return View("ViewToken", token);
             }
             return View(token);
         }
         return null;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Пример #6
0
 public int CreateToken(RegistrationToken objToken)
 {
     var parameters = new
     {
         Token = objToken.Token,
         OrganizationId = objToken.OrganizationId,
         DepartmentId = objToken.DepartmentId,
         CourseId = objToken.CourseId,
         ClassId = objToken.ClassId,
         SectionId = objToken.SectionId,
         RoleId = objToken.RoleId,
         CreatedBy = objToken.CreatedBy,
     };
     using (IDbConnection connection = OpenConnection())
     {
         const string storedProcedure = "usp_AddRegistrationToken";
         int rowsAffected = connection.Execute(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
         //SetIdentity<int>(connection, id => objToken.TokenId = id);
         return rowsAffected;
     }
 }
Пример #7
0
        public bool CreateOrganization(Organization objOrganization, RegistrationToken objToken)
        {
            var parameters = new
            {
                Address1 = objOrganization.Address1,
                Address2 = objOrganization.Address2,
                City = objOrganization.City,
                CountryId = objOrganization.CountryId,
                CreatedBy = objOrganization.CreatedBy,
                CreatedDate = DateTime.Now,
                Email = objOrganization.Email,
                OrganizationDesc = objOrganization.OrganizationDesc,
                OrganizationName = objOrganization.OrganizationName,
                OrganizationTypeId = objOrganization.OrganizationTypeId,
                Phone1 = objOrganization.Phone1,
                Phone2 = objOrganization.Phone2,
                RegisterationNumber = objOrganization.RegisterationNumber,
                StateId = objOrganization.StateId
            };
            using (IDbConnection connection = OpenConnection())
            {
                const string storedProcedure = "usp_addOrganization";
                int rowsAffected = 0;
                rowsAffected = connection.Execute(storedProcedure, parameters, commandType: CommandType.StoredProcedure);
                SetIdentity<int>(connection, id => objOrganization.OrganizationId = id);
                objToken.OrganizationId = objOrganization.OrganizationId;
                objToken.Email = objOrganization.Email;
                if (rowsAffected > 0)
                {
                    rowsAffected = 0;
                    rowsAffected = CreateRegistrationToken(objToken, connection);
                }

                if (rowsAffected > 0)
                {
                    return true;
                }
                return false;
            }
        }
Пример #8
0
 public ActionResult ViewToken(RegistrationToken token)
 {
     ViewBag.Token = token.Token;
     return View();
 }
Пример #9
0
        public void LoadSelectLists(ref RegistrationToken objToken)
        {
            SelectList OrganizationList = null;
            List<Organization> organizationList = new List<Organization>();
            List<Department> depList = new List<Department>();
            List<Course> crsList = new List<Course>();
            List<Class> clsList = new List<Class>();
            List<Section> secList = new List<Section>();
            List<SelectListItem> roleTypes = Enum.GetValues(typeof(StudentTracker.Core.Utilities.UserRoles)).Cast<StudentTracker.Core.Utilities.UserRoles>().Select(v => new SelectListItem
            {
                Text = v.ToString(),
                Value = ((int)v).ToString()
            }).ToList();

            if (User.IsInRole("SiteAdmin"))
            {
                OrganizationList = new SelectList(repository.Organizations(), "OrganizationId", "OrganizationName", "");
                objToken.RoleList = new SelectList(roleTypes, "Value", "Text");
            }
            else
            {
                var organization = repository.Organizations(_userStatistics.OrganizationId);
                ViewBag.OrganizationId = organization.OrganizationId;
                ViewBag.Organization = organization.OrganizationName;
                objToken.RoleList = new SelectList(roleTypes.Skip(2), "Value", "Text");
                crsList = repository.CourseByOrganization(_userStatistics.OrganizationId);
            }

            objToken.OrganizationList = OrganizationList;
            objToken.CourseList = new SelectList(crsList, "CourseId", "CourseName");
            objToken.ClassList = new SelectList(clsList, "ClassId", "ClassName");
            objToken.SectionList = new SelectList(secList, "SectionId", "SectionName");
            objToken.DepartmentList = new SelectList(depList, "DepartmentId", "DepartmentName");
        }
Пример #10
0
        public bool SendRegistrationEmailToStudents(string importId)
        {
            try
            {
                List<Student> objModelList = repository.GetImportedSudents(importId);
                StudentContext context = new StudentContext();
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                //  RegistrationToken tokenObj = new RegistrationToken();
                foreach (var student in objModelList)
                {
                    string token = UserStatistics.GenerateToken();

                    RegistrationToken tokenObj = new RegistrationToken();
                    tokenObj.ClassId = student.ClassId;
                    tokenObj.CourseId = student.CourseId;
                    tokenObj.DepartmentId = student.DepartmentId;
                    tokenObj.OrganizationId = student.OrganizationId;
                    tokenObj.RoleId = Convert.ToInt32(UserRoles.Student);
                    tokenObj.SectionId = student.SectionId;
                    tokenObj.Token = token;
                    tokenObj.Email = student.Email;
                    tokenObj.ImportId = importId;
                    tokenObj.InsertedOn = DateTime.Now;
                    tokenObj.StudentId = student.StudentId;
                    context.RegistrationTokens.Add(tokenObj);
                    parameters.Add(token, student.Email);
                }

                context.SaveChanges();

                Task.Factory.StartNew(() => SendEmails(parameters));

                //SendEmails(parameters);
                return true;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }