Ejemplo n.º 1
0
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);

            dbContext = new MobileServiceContext();
            controllerContext.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            DomainManager = new EntityDomainManager <Album>(dbContext, Request, enableSoftDelete: IsSoftDeleteEnabled());
        }
Ejemplo n.º 2
0
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            MobileServiceContext context = new MobileServiceContext();
            var softDeleteEnabled        = Convert.ToBoolean(ConfigurationManager.AppSettings["enableSoftDelete"]);

            DomainManager = new EntityDomainManager <Image>(context, Request, enableSoftDelete: softDeleteEnabled);
        }
Ejemplo n.º 3
0
        private static void AddUser(string identifier, MobileServiceContext ctx)
        {
            var u =
                ctx.Users.Add(
                    new User {
                Id = identifier,
            });

            ctx.SaveChanges();
        }
        // GET api/PushRegistration
        public async Task Post([FromBody] DeviceInstallationInfo deviceInstallInfo)
        {
            bool isChanged    = false;
            var  ctx          = new MobileServiceContext();
            var  registration = ctx.DeviceRegistrations.Where(x => x.InstallationId == deviceInstallInfo.InstallationId);

            if (registration.Count() == 0)
            {
                NotificationPlatform?plat = await GetNotificationPlatform(deviceInstallInfo.InstallationId);

                if (null != plat)
                {
                    var newRegistration = new Common.Models.DeviceRegistration()
                    {
                        Id             = Guid.NewGuid().ToString(),
                        InstallationId = deviceInstallInfo.InstallationId,
                        UserId         = deviceInstallInfo.UserId,
                        Platform       = plat.Value
                    };

                    ctx.DeviceRegistrations.Add(newRegistration);
                    isChanged = true;
                }
            }
            else
            {
                var reg = registration.First();

                if (reg.UserId != deviceInstallInfo.UserId)
                {
                    reg.UserId = deviceInstallInfo.UserId;
                    isChanged  = true;
                }
            }

            try
            {
                if (isChanged)
                {
                    ctx.SaveChanges();
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 5
0
        // GET api/ManageUser
        public async Task <string> Get()
        {
            string username = await GetUserId(Request, this.User);

            Debug.WriteLine($"Username is: {username}");

            using (var ctx = new MobileServiceContext()) {
                var user = ctx.Users.Find(username);

                if (user == null)
                {
                    AddUser(username, ctx);
                }

                return(username);
            }
        }
Ejemplo n.º 6
0
        // POST: api/Like
        public async Task <bool> Post([FromBody] Dictionary <string, string> imageInfo)
        {
            using (var ctx = new MobileServiceContext()) {
                var imageId = imageInfo["imageId"]; // resolve imageId to a value before using it in a LINQ expression
                var image   = ctx.Images.Include("User").SingleOrDefault(x => x.Id == imageId);

                if (image != null)
                {
                    var registrations = ctx.DeviceRegistrations.Where(x => x.UserId == image.UserId);

                    //Send plat-specific message to all installation one by one
                    string message = "Someone has liked your image";
                    foreach (var registration in registrations)
                    {
                        await SendPush(message, registration);
                    }

                    return(true);
                }

                return(false);
            }
        }
        public async Task Delete([FromBody] DeviceInstallationInfo deviceInstallInfo)
        {
            var ctx          = new MobileServiceContext();
            var registration = ctx.DeviceRegistrations.Where(x => x.InstallationId == deviceInstallInfo.InstallationId);

            if (registration.Count() > 0)
            {
                var reg = registration.First();

                await Notifier.Instance.RemoveRegistration(deviceInstallInfo.InstallationId);

                ctx.DeviceRegistrations.Remove(reg);

                try
                {
                    ctx.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }