Beispiel #1
0
 public bool CourseAdd(Entities db, string name, State state, int ordinal, bool range)
 {
     try
     {
         var course = new Catalog
         {
             Id = db.GetId(),
             ParentId = HomoryCoreConstant.CourseOtherId,
             TopId = range ? Guid.Empty : (Guid?)null,
             Name = name,
             State = state,
             Ordinal = ordinal,
             Type = CatalogType.课程
         };
         var ex = db.Catalog.SingleOrDefault(o => o.Name == name && o.Type == CatalogType.课程);
         if (ex == null)
         {
             db.Catalog.Add(course);
             db.SaveChanges();
         }
         else
         {
             ex.State = state;
             ex.Ordinal = ordinal;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Beispiel #2
0
 protected dynamic UserSignOn(Entities db, string account, string password)
 {
     dynamic output = new ExpandoObject();
     output.Ok = false;
     output.Data = new ExpandoObject();
     try
     {
         var user = db.User.SingleOrDefault(o => o.Account == account && o.State < State.删除);
         if (user == null ||
             !password.Equals(HomoryCryptor.Decrypt(user.Password, user.CryptoKey, user.CryptoSalt),
                 StringComparison.OrdinalIgnoreCase))
         {
             output.Data.Message = "请输入正确的账号和密码";
             output.Entity = null;
             return output;
         }
         if (user.State == State.停用)
         {
             output.Data.Message = "用户已被停用";
             output.Entity = null;
             return output;
         }
         if (user.State == State.默认 || user.State == State.审核)
         {
             Session[HomoryConstant.SessionRegisterId] = user.Id;
             output.Ok = true;
             output.Data.Redirect = true;
             output.Data.RedirectUrl = Application["Sso"] + "Go/ToVerify";
             output.Entity = null;
             return output;
         }
         var online = user.UserOnline.SingleOrDefault();
         if (online == null)
         {
             online = new UserOnline
             {
                 Id = db.GetId(),
                 UserId = user.Id,
                 TimeStamp = DateTime.Now
             };
             db.UserOnline.Add(online);
         }
         else
         {
             online.TimeStamp = DateTime.Now;
         }
         db.SaveChanges();
         var cookie = new HttpCookie(HomoryConstant.CookieOnlineId, online.Id.ToString().ToUpper());
         var expire = int.Parse(db.ApplicationPolicy.Single(o => o.Name == "UserCookieExpire" && o.ApplicationId == Guid.Empty).Value);
         cookie.Expires = DateTime.Now.AddMinutes(expire);
         Response.SetCookie(cookie);
         Session[HomoryConstant.SessionOnlineId] = online.Id;
         output.Ok = true;
         output.Data.Redirect = true;
         var query = Server.UrlDecode(Request.QueryString["SsoRedirect"]);
         var query_x = Request.QueryString;
         if (string.IsNullOrEmpty(Request.QueryString["Permanent"]))
         {
             if (string.IsNullOrWhiteSpace(Request.QueryString["SsoRedirect"]))
             {
                 if (user.Type == UserType.教师)
                     output.Data.RedirectUrl = string.Format(string.Format("SsoRedirect".FromWebConfig() == "" ? Application["Sso"] + "Go/Board" : "SsoRedirect".FromWebConfig(), user.Account, HomoryCryptor.Decrypt(user.Password, user.CryptoKey, user.CryptoSalt)));
                 else
                     output.Data.RedirectUrl = string.Format(string.Format("SsoRedirectOther".FromWebConfig() == "" ? Application["Sso"] + "Go/Board" : "SsoRedirectOther".FromWebConfig(), user.Account, HomoryCryptor.Decrypt(user.Password, user.CryptoKey, user.CryptoSalt)));
             }
             else
             {
                 string url;
                 if (!string.IsNullOrWhiteSpace(Request.QueryString["OnlineId"]))
                 {
                     url = query;
                 }
                 else
                 {
                     if (query.IndexOf('&') <= 0)
                     {
                         url = string.Format("{0}?OnlineId={1}", query, user.UserOnline.Single().Id);
                     }
                     else
                     {
                         var index = query.IndexOf('&');
                         url =
                             Server.UrlDecode(query.Remove(index, 1)
                                 .Insert(index, string.Format("?OnlineId={0}&", user.UserOnline.Single().Id)));
                     }
                 }
                 foreach (var qx in query_x)
                 {
                     if (!qx.ToString().Equals("SsoRedirect", StringComparison.OrdinalIgnoreCase))
                         url += "&" + qx + "=" + query_x[qx.ToString()];
                 }
                 output.Entity = null;
                 if (string.IsNullOrWhiteSpace(url))
                 {
                     if (user.Type == UserType.教师)
                         string.Format(string.Format("SsoRedirect".FromWebConfig() == "" ? Application["Sso"] + "Go/Board" : "SsoRedirect".FromWebConfig(), user.Account, HomoryCryptor.Decrypt(user.Password, user.CryptoKey, user.CryptoSalt)));
                     else
                         string.Format(string.Format("SsoRedirectOther".FromWebConfig() == "" ? Application["Sso"] + "Go/Board" : "SsoRedirectOther".FromWebConfig(), user.Account, HomoryCryptor.Decrypt(user.Password, user.CryptoKey, user.CryptoSalt)));
                 }
                 else
                 {
                     output.Data.RedirectUrl = url;
                 }
             }
         }
         else
         {
             output.Entity = user;
             output.Data.RedirectUrl = "*Permanent*";
         }
         return output;
     }
     catch (Exception exception)
     {
         output.Data.Message = exception.Message;
         output.Entity = null;
         return output;
     }
 }
Beispiel #3
0
 public bool StudentAdd(Entities db, Guid campusId, Guid classId, int ordinal, string name, string account, string passwordInitial, State state, string uniqueId, string idCard, bool? gender, DateTime? birthday, string nationality, string birthplace, string address, string charger, string chargerContact)
 {
     try
     {
         string key, salt;
         var password = HomoryCryptor.Encrypt(passwordInitial, out key, out salt);
         if (HomoryContext.Value.Student.Count(o => o.IDCard == idCard && o.UniqueId == uniqueId && o.User.State == State.启用) == 0)
         {
             var user = new User
             {
                 Id = db.GetId(),
                 Account = account,
                 RealName = name,
                 DisplayName = name,
                 Stamp = Guid.NewGuid(),
                 Type = UserType.学生,
                 Password = password,
                 PasswordEx = null,
                 CryptoKey = key,
                 CryptoSalt = salt,
                 Icon = "~/Common/默认/用户.png",
                 State = state,
                 Ordinal = ordinal,
                 Description = null
             };
             var userStudent = new Homory.Model.Student
             {
                 Id = user.Id,
                 UniqueId = uniqueId,
                 Gender = gender,
                 Birthday = birthday,
                 Birthplace = birthplace,
                 Address = address,
                 Nationality = nationality,
                 IDCard = idCard,
                 Charger = charger,
                 ChargerContact = chargerContact
             };
             var relation = new DepartmentUser
             {
                 DepartmentId = classId,
                 UserId = user.Id,
                 TopDepartmentId = campusId,
                 Type = DepartmentUserType.班级学生,
                 State = State.启用,
                 Ordinal = 0,
                 Time = DateTime.Now
             };
             db.User.Add(user);
             db.Student.Add(userStudent);
             db.DepartmentUser.Add(relation);
         }
         else
         {
             var nowU = HomoryContext.Value.Student.Single(o => o.IDCard == idCard && o.UniqueId == uniqueId && o.User.State == State.启用);
             var nowQ = HomoryContext.Value.DepartmentUser.Where(o => o.DepartmentId == classId && o.UserId == nowU.Id && o.Type == DepartmentUserType.班级学生);
             if (nowQ.Count() == 0)
             {
                 var relation = new DepartmentUser
                 {
                     DepartmentId = classId,
                     UserId = nowU.Id,
                     TopDepartmentId = campusId,
                     Type = DepartmentUserType.班级学生,
                     State = State.启用,
                     Ordinal = 0,
                     Time = DateTime.Now
                 };
                 db.DepartmentUser.Add(relation);
             }
             else
             {
                 HomoryContext.Value.DepartmentUser.Where(o => o.DepartmentId == classId && o.UserId == nowU.Id && o.Type == DepartmentUserType.班级学生).Update(o => new DepartmentUser { Time = DateTime.Now, State = State.启用 });
             }
         }
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }