Exemplo n.º 1
0
        public static UserDevice AddUserDevice(string username, string deviceType, int deviceMemoryResource, int deviceProcRating, String gcmCode)
        {
            try {
                marcdissertation_dbEntities ctxt = new marcdissertation_dbEntities();
                if (ctxt.UserDevices.Count(x => x.GCMCode == gcmCode) > 0) {
                    throw new Exception("Device can only be assigned to single user. Assigned to: " + ctxt.UserDevices.First(x => x.GCMCode == gcmCode).User.Username);
                }

                UserDevice ud = new UserDevice();
                ud.Username = username;
                ud.DeviceType = deviceType;
                ud.DeviceMemoryResource = deviceMemoryResource;
                ud.DeviceProcRating = deviceProcRating;
                ud.GCMCode = gcmCode;
                ud.context = ctxt;
                ud = ud.context.UserDevices.Add(ud);

                IEnumerable<System.Data.Entity.Validation.DbEntityValidationResult> errors = ud.context.GetValidationErrors();

                if (errors.Count() > 0) {
                    throw App.ExceptionFormatter(errors);
                }

                ud.context.SaveChanges();
                return ud;
            } catch (Exception e) {
                if (new marcdissertation_dbEntities().Users.Select(x => x.Username.Equals(username)).Count() == 0) {
                    throw new Exception("Username must exist");
                }

                throw e;
            }
        }
Exemplo n.º 2
0
        public BusinessLayer.UserDevice AddUserDeviceNoGCMCode(String at, String username, string deviceType, int deviceMemoryResource, int deviceProcRating)
        {
            //TODO: Fix auth here
//            AuthenticationToken oAt = new AuthSvc().AuthUser(at);
            BusinessLayer.UserDevice ud = BusinessLayer.UserDevice.AddUserDevice(username, deviceType, deviceMemoryResource, deviceProcRating);
            return(ud);
        }
Exemplo n.º 3
0
        public void DeleteUserDevice(String at, int deviceId)
        {
            BusinessLayer.UserDevice ud = BusinessLayer.UserDevice.Populate(deviceId);

            AuthenticationToken oAt = new AuthSvc().AuthUser(at, ud.User.UserId);

            if (ud.User.Username.Equals(oAt.Username))
            {
                ud.Delete();
            }
        }
Exemplo n.º 4
0
        public int GetDeviceId(String at, String gcmId)
        {
            AuthenticationToken oAt = new AuthSvc().AuthUser(at);

            BusinessLayer.UserDevice ud = BusinessLayer.UserDevice.Populate(gcmId);

            if (BusinessLayer.User.Populate(oAt.Username).UserId != ud.User.UserId)
            {
                throw new Exception("Error: Device is not tied to authenticating in user");
            }
            return(ud.DeviceId);
        }
Exemplo n.º 5
0
        public void ModifyUserDevice(String at, String gcmCode, int deviceId = -1)
        {
            if (deviceId != -1)
            {
                BusinessLayer.UserDevice ud = BusinessLayer.UserDevice.Populate(deviceId);

                ud.GCMCode = gcmCode;

                ud.Save();
            }
            else
            {
                throw new Exception("Device must be selected.");
            }
        }