public int UpdateSSA(DAL.Entity.SaudiStudentAssociation SSA)
 {
     try
     {
         _ISSARepository.Update(SSA);
         return(_ISSARepository.Save());
     }
     catch (Exception exception)
     {
         exception.Log();
         return(0);
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int        ssaId       = 0;
            SSAManager _SSAManager = new SSAManager();

            DAL.Entity.SaudiStudentAssociation obj = null;
            var user = AspNetSecurityHelper.currentAppUser;

            if (user != null)
            {
                if (user.UserTypeId == 1 && int.TryParse(ddlSSA.SelectedValue, out ssaId)) // Administrator
                {
                    obj = _SSAManager.GetSSA(ssaId);
                }
                else
                {
                    if (user.UniversityId.HasValue)
                    {
                        obj = _SSAManager.GetSSAByUniversityId(user.UniversityId.Value);
                    }
                    obj.AdministratorId = user.Id;
                }
                obj.Name       = txtName.Text;
                obj.Website    = txtWebsite.Text;
                obj.SocialInfo = txtSocialInfo.Text;
                obj.Phone      = txtPhone.Text;
                obj.Fax        = txtFax.Text;
                obj.Street     = txtStreet.Text;

                int zipcode = 0;
                if (int.TryParse(txtZipCode.Text, out zipcode))
                {
                    obj.ZipCode = zipcode;
                }

                int state = 0;
                if (int.TryParse(ddlState.SelectedValue, out state))
                {
                    obj.StateId = state;
                }

                int city = 0;
                if (int.TryParse(ddlCity.SelectedValue, out city))
                {
                    obj.CityId = city;
                }

                int uni = 0;
                if (int.TryParse(ddlUniversity.SelectedValue, out uni))
                {
                    obj.UniversityId = uni;
                }

                int i = 0;
                if (obj.Id == 0)
                {
                    obj.CreatedBy   = user.UserName;
                    obj.CreatedDate = DateTime.Now;
                    obj.DeletedFlag = false;
                    i         = _SSAManager.AddSSA(obj);
                    Operation = (String)GetGlobalResourceObject("HCMResource", "Add");
                }
                else
                {
                    obj.LastUpdatedBy   = user.UserName;
                    obj.LastUpdatedDate = DateTime.Now;
                    i         = _SSAManager.UpdateSSA(obj);
                    Operation = (String)GetGlobalResourceObject("HCMResource", "Update");
                }
                if (i != 0)
                {
                    ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationSuccess"), Operation), "", Common.msgType.alertMessageSuccess);
                    FillData();
                }
                else
                {
                    ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), Operation), "", Common.msgType.alertMessageDanger);
                }
            }
            else
            {
                Response.Redirect("/");
            }
        }
        private void FillData()
        {
            int        ssaId       = 0;
            SSAManager _SSAManager = new SSAManager();

            DAL.Entity.SaudiStudentAssociation obj = null;
            var user = AspNetSecurityHelper.currentAppUser;

            if (user != null)
            {
                if (user.UserTypeId == 1 && int.TryParse(ddlSSA.SelectedValue, out ssaId)) // Administrator
                {
                    obj = _SSAManager.GetSSA(ssaId);
                    ddlUniversity.Enabled = true;
                    divAdminView.Visible  = true;
                }
                else
                {
                    if (user.UniversityId.HasValue)
                    {
                        obj = _SSAManager.GetSSAByUniversityId(user.UniversityId.Value);
                    }
                    ddlUniversity.Enabled = false;
                    divAdminView.Visible  = false;
                }
            }
            if (obj != null)
            {
                txtName.Text       = obj.Name;
                txtWebsite.Text    = obj.Website;
                txtSocialInfo.Text = obj.SocialInfo;
                txtPhone.Text      = obj.Phone;
                txtFax.Text        = obj.Fax;
                txtStreet.Text     = obj.Street;

                if (obj.ZipCode.HasValue)
                {
                    txtZipCode.Text = obj.ZipCode.Value.ToString();
                }
                else
                {
                    txtZipCode.Text = String.Empty;
                }

                if (obj.StateId.HasValue)
                {
                    ddlState.ClearSelection();
                    ddlState.Items.FindByValue(obj.StateId.Value.ToString()).Selected = true;
                    FillCity(obj.StateId.Value);
                }
                else
                {
                    ddlState.SelectedIndex = 0;
                }

                if (obj.CityId.HasValue)
                {
                    ddlCity.ClearSelection();
                    ddlCity.Items.FindByValue(obj.CityId.Value.ToString()).Selected = true;
                }
                else
                {
                    ddlCity.SelectedIndex = 0;
                }

                if (obj.UniversityId.HasValue)
                {
                    ddlUniversity.ClearSelection();
                    ddlUniversity.Items.FindByValue(obj.UniversityId.Value.ToString()).Selected = true;
                }
                else
                {
                    ddlUniversity.SelectedIndex = 0;
                }

                Operation = (String)GetGlobalResourceObject("HCMResource", "UpdateExisting");
            }
            else
            {
                Operation = (String)GetGlobalResourceObject("HCMResource", "AddNew");
            }
        }
Beispiel #4
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string operation = "";
            string userId    = e.CommandArgument.ToString();

            if (!String.IsNullOrEmpty(userId))
            {
                var user = AspNetSecurityHelper.FindUserById(userId);
                if (user != null)
                {
                    if (e.CommandName == "ActiveUser")
                    {
                        if (user.LockoutEndDateUtc != null)
                        {
                            //user.Active = true;
                            user.AccessFailedCount = 0;
                            user.LockoutEndDateUtc = null;
                            operation = (String)GetGlobalResourceObject("HCMResource", "Active");
                        }
                        else
                        {
                            //user.Active = false;
                            user.AccessFailedCount = 5;
                            user.LockoutEndDateUtc = DateTime.Now.AddDays(365);
                            operation = (String)GetGlobalResourceObject("HCMResource", "Lock");
                        }
                    }
                    else if (e.CommandName == "GrantPermission")
                    {
                        user.Active = true;
                        var roles = user.Roles;
                        if (roles.Count() == 0)
                        {
                            var role = AspNetSecurityHelper.FindRoleByName("Supervisor");
                            if (role != null)
                            {
                                AspNetSecurityHelper.InsertUserToRole(user.Id, role.Id);
                            }
                        }
                        operation = (String)GetGlobalResourceObject("HCMResource", "GrantPermission");
                    }
                    IdentityResult r = AspNetSecurityHelper.UpdateUser(user);
                    if (r.Succeeded)
                    {
                        SSAManager _SSAManager = new SSAManager();
                        DAL.Entity.SaudiStudentAssociation obj = null;
                        if (user != null)
                        {
                            if (user.UniversityId.HasValue)
                            {
                                obj = _SSAManager.GetSSAByUniversityId(user.UniversityId.Value);
                            }
                            //obj = _SSAManager.GetSSAByAdministratorId(user.Id);
                            if (obj == null)
                            {
                                obj = new DAL.Entity.SaudiStudentAssociation();
                            }
                            obj.AdministratorId = user.Id;

                            if (user.UniversityId.HasValue && user.UniversityId.Value != 0)
                            {
                                obj.UniversityId = user.UniversityId.Value;
                            }

                            int i = 0;
                            if (obj.Id == 0)
                            {
                                obj.CreatedBy   = user.UserName;
                                obj.CreatedDate = DateTime.Now;
                                obj.DeletedFlag = false;
                                i = _SSAManager.AddSSA(obj);
                            }
                            else
                            {
                                obj.LastUpdatedBy   = user.UserName;
                                obj.LastUpdatedDate = DateTime.Now;
                                i = _SSAManager.UpdateSSA(obj);
                            }
                        }

                        ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationSuccess"), operation), "", Common.msgType.alertMessageSuccess);
                    }
                    else
                    {
                        string errorStr = (String)GetGlobalResourceObject("HCMResource", "ActiveError");
                        foreach (string s in r.Errors)
                        {
                            errorStr += ", " + s.ToString();
                        }
                        ucAlertMessage.AlertMessage(errorStr, "", Common.msgType.alertMessageDanger);
                    }
                }
                else
                {
                    ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), operation), "", Common.msgType.alertMessageDanger);
                }
                FillData();
            }
            else
            {
                ucAlertMessage.AlertMessage(String.Format((String)GetGlobalResourceObject("HCMResource", "OperationError"), operation), "", Common.msgType.alertMessageDanger);
            }
        }