Esempio n. 1
0
        public static User GetUser(string name)
        {
            User user = null;

            using (var db = new HorseData())
            {
                user = db.Users.Where(u => u.NTAccount == name).FirstOrDefault();

                if (user == null)
                {
                    user              = new Horse.WebSite.Models.User();
                    user.NTAccount    = name;
                    user.CreateDt     = DateTime.Now;
                    user.LastUpdateDt = DateTime.Now;
                    setUserData(user);
                    db.Users.Add(user);
                }
                else if (user.LastUpdateDt.Value.AddDays(1).CompareTo(DateTime.Now) < 0)
                {
                    setUserData(user);
                    user.LastUpdateDt = DateTime.Now;
                }

                db.SaveChanges();
            }

            return(user);
        }
        public IHttpActionResult Register(RegisterInfo info)
        {
            var um = db.UserMachines.Include(u => u.User).Include(u => u.Machine).Where(u => u.Uid == currentUser.Id && u.Machine.Name == info.HostName).FirstOrDefault();

            if (um != null)
            {
                um.Machine.IPAddress = info.IPAddress;
            }
            else
            {
                um = new UserMachine()
                {
                    Uid = currentUser.Id, Machine = new Machine()
                    {
                        IPAddress = info.IPAddress, Name = info.HostName
                    }
                };
                db.UserMachines.Add(um);
            }
            db.SaveChanges();
            return(Ok());
        }