Пример #1
0
        protected void SchoolSelectSubmit_Click(object sender, EventArgs e)
        {
            FormsAuthenticationTicket tkt;
            string     cookiestr;
            HttpCookie ck;

            tkt       = new FormsAuthenticationTicket(1, Session["UserName"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
            cookiestr = FormsAuthentication.Encrypt(tkt);
            ck        = new HttpCookie("SmacCookie", cookiestr);


            StringBuilder sb = new StringBuilder();

            var genders = GenderEntity.GetGenders();

            genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":"));
            sb.Remove(sb.Length - 1, 1);

            ck.Values.Add("UserId", Session["UserId"].ToString());
            ck.Values.Add("FirstName", Session["FirstName"].ToString());
            ck.Values.Add("MiddleName", Session["MiddleName"].ToString());
            ck.Values.Add("LastName", Session["LastName"].ToString());
            ck.Values.Add("PhoneNumber", Session["PhoneNumber"].ToString());
            ck.Values.Add("Email", Session["Email"].ToString());
            ck.Values.Add("UserName", Session["UserName"].ToString());
            ck.Values.Add("Gender", Session["Gender"].ToString());
            ck.Values.Add("SchoolName", ddList_SchoolSelect.SelectedItem.Text);
            ck.Values.Add("SchoolId", ddList_SchoolSelect.SelectedItem.Value);
            ck.Values.Add("Genders", sb.ToString());

            Response.Cookies.Add(ck);
            Session["UpdateCookie"] = "no";

            Response.Redirect("/Home.aspx");
        }
        public async Task <GenderEntity> UpdateGenderByIdAsync(GenderEntity genderEntity, CancellationToken token)
        {
            _dbContext.Genders.Update(genderEntity);
            await _dbContext.SaveChangesAsync(token);

            return(genderEntity);
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] GenderEntity genderEntity)
        {
            if (id != genderEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(genderEntity);
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There is already that gender");
                    }
                }
            }
            return(View(genderEntity));
        }
        public async Task <GenderEntity> CreateGenderAsync(GenderEntity genderEntity, CancellationToken token)
        {
            await _dbContext.Genders.AddAsync(genderEntity, token);

            await _dbContext.SaveChangesAsync(token);

            return(genderEntity);
        }
Пример #5
0
        protected GenderModel ConvertToModel(GenderEntity e)
        {
            var result = new GenderModel()
            {
                Id   = e.Id,
                Code = (int)e.Code,
                Name = e.Name
            };

            return(result);
        }
Пример #6
0
        public GenderResponse ToGenderResponse(GenderEntity genderEntity)
        {
            if (genderEntity == null)
            {
                return(null);
            }

            return(new GenderResponse
            {
                Id = genderEntity.Id,
                Name = genderEntity.Name
            });
        }
Пример #7
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            try
            {
                var usr = UserCredentialEntity.Authenticate(Request.Form["username"].Trim(), Request.Form["password"]);

                FormsAuthenticationTicket tkt;
                string     cookiestr;
                HttpCookie ck;
                tkt       = new FormsAuthenticationTicket(1, Request.Form["username"].Trim(), DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
                cookiestr = FormsAuthentication.Encrypt(tkt);
                ck        = new HttpCookie("SmacCookie", cookiestr);


                StringBuilder sb = new StringBuilder();

                var genders = GenderEntity.GetGenders();

                genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":"));
                sb.Remove(sb.Length - 1, 1);

                ck.Values.Add("UserId", usr.UserId);
                ck.Values.Add("FirstName", usr.FirstName);
                ck.Values.Add("LastName", usr.LastName);
                ck.Values.Add("PhoneNumber", usr.PhoneNumber);
                ck.Values.Add("Email", usr.EmailAddress);
                ck.Values.Add("MiddleName", usr.MiddleName);
                ck.Values.Add("UserName", usr.UserCredential.UserName);
                ck.Values.Add("Gender", usr.GenderType);
                ck.Values.Add("Genders", sb.ToString());

                var school = SchoolEntity.GetUsersSchools(usr.UserId);

                if (school.Count == 1)
                {
                    ck.Values.Add("SchoolName", school[0].SchoolName);
                    ck.Values.Add("SchoolId", school[0].SchoolId.ToString());
                }

                Response.Cookies.Add(ck);

                FormsAuthentication.RedirectFromLoginPage(Request.Form["username"].Trim(), false);
            }
            catch (Exception ex)
            {
                loginStatus.Text      = ex.Message;
                loginStatus.ForeColor = System.Drawing.Color.Red;
            }
        }
Пример #8
0
        // GET: Genders/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GenderEntity genderEntity = await _context.Genders.FindAsync(id);

            if (genderEntity == null)
            {
                return(NotFound());
            }
            return(View(genderEntity));
        }
        public bool Delete(GenderEntity gender)
        {
            try
            {
                TIMSDBEntities entity = new TIMSDBEntities();
                tblGender      Gender = entity.tblGenders.Where(x => x.ID == gender.ID).FirstOrDefault();

                entity.tblGenders.Remove(Gender);
                entity.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public GenderEntity GetSingle(int ID)
        {
            try
            {
                TIMSDBEntities entity = new TIMSDBEntities();

                tblGender    Gender = entity.tblGenders.Where(x => x.ID == ID).FirstOrDefault();
                GenderEntity gender = new GenderEntity();
                gender.ID    = Gender.ID;
                gender.Title = Gender.Title;

                return(gender);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public bool Save(GenderEntity gender)
        {
            try
            {
                tblGender Gender = new tblGender();

                Gender.ID    = gender.ID;
                Gender.Title = gender.Title;

                TIMSDBEntities entity = new TIMSDBEntities();
                entity.tblGenders.Add(Gender);
                entity.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #12
0
        // GET: Genders/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            GenderEntity genderEntity = await _context.Genders
                                        .FirstOrDefaultAsync(m => m.Id == id);

            if (genderEntity == null)
            {
                return(NotFound());
            }

            _context.Genders.Remove(genderEntity);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public bool Update(GenderEntity gender)
        {
            try
            {
                tblGender newGender = new tblGender();

                newGender.ID    = gender.ID;
                newGender.Title = gender.Title;

                TIMSDBEntities entity    = new TIMSDBEntities();
                tblGender      oldGender = entity.tblGenders.Where(x => x.ID == gender.ID).FirstOrDefault();
                entity.Entry(oldGender).CurrentValues.SetValues(newGender);
                entity.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public List <GenderEntity> GetAll()
        {
            try
            {
                List <GenderEntity> GenderEntities = new List <GenderEntity>();
                TIMSDBEntities      entity         = new TIMSDBEntities();
                List <tblGender>    Genders        = entity.tblGenders.ToList();

                foreach (tblGender Gender in Genders)
                {
                    GenderEntity gender = new GenderEntity();
                    gender.ID    = Gender.ID;
                    gender.Title = Gender.Title;

                    GenderEntities.Add(gender);
                }
                return(GenderEntities);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }

            var userId = Request.Cookies["SmacCookie"]["UserId"];

            this.userRole.Value    = Database.Helpers.GetUserRole(userId).ToString();
            this.newMessages.Value = PrivateMessageEntity.CheckForNewMessages(userId).ToString();


            if (Session["UpdateCookie"] != null && Session["UpdateCookie"].ToString() == "yes")
            {
                FormsAuthenticationTicket tkt;
                string     cookiestr;
                HttpCookie ck;
                tkt       = new FormsAuthenticationTicket(1, Session["UserName"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
                cookiestr = FormsAuthentication.Encrypt(tkt);
                ck        = new HttpCookie("SmacCookie", cookiestr);


                StringBuilder sb = new StringBuilder();

                var genders = GenderEntity.GetGenders();

                genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":"));
                sb.Remove(sb.Length - 1, 1);

                ck.Values.Add("UserId", Session["UserId"].ToString());
                ck.Values.Add("FirstName", Session["FirstName"].ToString());
                ck.Values.Add("MiddleName", Session["MiddleName"].ToString());
                ck.Values.Add("LastName", Session["LastName"].ToString());
                ck.Values.Add("PhoneNumber", Session["PhoneNumber"].ToString());
                ck.Values.Add("Email", Session["Email"].ToString());
                ck.Values.Add("UserName", Session["UserName"].ToString());
                ck.Values.Add("Gender", Session["Gender"].ToString());
                ck.Values.Add("SchoolName", Session["SchoolName"].ToString());
                ck.Values.Add("SchoolId", Session["SchoolId"].ToString());
                ck.Values.Add("Genders", sb.ToString());

                Response.Cookies.Add(ck);
                Session["UpdateCookie"] = "no";
            }
            else
            {
                Session["UserId"]      = Request.Cookies["SmacCookie"]["UserId"];
                Session["FirstName"]   = Request.Cookies["SmacCookie"]["FirstName"];
                Session["MiddleName"]  = Request.Cookies["SmacCookie"]["MiddleName"];
                Session["LastName"]    = Request.Cookies["SmacCookie"]["LastName"];
                Session["PhoneNumber"] = Request.Cookies["SmacCookie"]["PhoneNumber"];
                Session["Email"]       = Request.Cookies["SmacCookie"]["Email"];
                Session["UserName"]    = Request.Cookies["SmacCookie"]["UserName"];
                Session["Gender"]      = Request.Cookies["SmacCookie"]["Gender"];
                Session["SchoolName"]  = Request.Cookies["SmacCookie"]["SchoolName"];
                Session["SchoolId"]    = Request.Cookies["SmacCookie"]["SchoolId"];
                Session["Genders"]     = Request.Cookies["SmacCookie"]["Genders"];

                if (Session["SchoolName"] != null)
                {
                    schoolBanner.Visible   = true;
                    schoolBanner.InnerHtml = Request.Cookies["SmacCookie"]["SchoolName"];
                }
            }
        }