Exemplo n.º 1
0
        public async Task <IActionResult> Delete([FromBody] Post post)
        {
            var currentUser = await GetCurrentUserAsync();

            if (currentUser == null)
            {
                return(Json(new Array[] {}));
            }

            if (ModelState.IsValid)
            {
                if (post.Id != null && post.User != null && post.User.Id != null)
                {
                    var selectedDbUser = _context.Users.SingleOrDefault(u => u.OwnerId == post.User.Id);
                    if (selectedDbUser != null && selectedDbUser.IsLoggedIn && checkWithCurrentUser(selectedDbUser))
                    {
                        var selectedDbPost = _context.Posts.SingleOrDefault(u => u.Id == post.Id);
                        _context.Remove(selectedDbPost);
                        _context.SaveChanges();
                    }
                }
            }

            return(Json(await GetUsers()));
        }
Exemplo n.º 2
0
 public static void Delete(int accountId, int dashboardId)
 {
     using (var context = new CoreContext())
     {
         Dashboard dashboard = context.Dashboards.Find(dashboardId);
         if (dashboard != null && dashboard.AccountId == accountId)
         {
             context.Remove(dashboard);
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
 public static void Delete(int accountId, int metricId)
 {
     using (var context = new CoreContext())
     {
         Metric metric = context.Metrics.Find(metricId);
         if (metric != null && metric.AccountId == accountId)
         {
             context.Remove(metric);
             context.SaveChanges();
         }
     }
 }
Exemplo n.º 4
0
 public static void Delete(int accountId, int widgetId)
 {
     using (var context = new CoreContext())
     {
         Widget widget = context.Widgets.Find(widgetId);
         if (widget != null)
         {
             Dashboard dashboard = context.Dashboards.Find(widget.DashboardId);
             if (dashboard.AccountId == accountId)
             {
                 context.Remove(widget);
                 context.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 5
0
        private int PopChannel(string StoredChannelUniqueId, int?ChannelId, int?ChannelParentId = null, int?ChannelOrder = null)
        {
            using (var db = new CoreContext())
            {
                // Remove the stored channel
                Models.StoredChannels storedChannel;

                if (ChannelId != null)
                {
                    storedChannel = db.StoredChannels.SingleOrDefault(channel => channel.ChannelId == ChannelId && channel.SubscriberId == this.Subscriber.SubscriberId);
                }
                else
                {
                    storedChannel = db.StoredChannels.SingleOrDefault(channel => channel.StoredChannelUniqueId == StoredChannelUniqueId && channel.SubscriberId == this.Subscriber.SubscriberId);
                }

                if (storedChannel == null)
                {
                    throw new Exception("Stored channel does not exist");
                }

                db.Remove(storedChannel);

                // Create the new channel
                var channelMod = storedChannel.ToChannelModification();

                if (channelMod.IconId == 0)
                {
                    channelMod.IconId = null;
                }

                if (ChannelParentId != null)
                {
                    channelMod.ParentChannelId = (uint?)ChannelParentId;
                }

                if (ChannelOrder != null)
                {
                    channelMod.ChannelOrder = (uint?)ChannelOrder;
                }

                SingleValueResponse <uint?> creationResponse = null;

                try
                {
                    //TODO: Fix the incorrect input format bug in ts3querylib
                    creationResponse = ServerQueryConnection.QueryRunner.CreateChannel(channelMod);

                    if (creationResponse.IsErroneous)
                    {
                        throw new Exception("Could not pop stored channel: " + creationResponse.ResponseText + " (" + creationResponse.ErrorMessage + ")");
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message != "Input string was not in a correct format.")
                    {
                        // Uh oh, something else happened
                        throw ex;
                    }
                }

                if (creationResponse.Value == null)
                {
                    throw new Exception("Could not pop stored channel, no result given.");
                }

                // Save changes
                db.SaveChanges();
                return((int)creationResponse.Value); // Return the new channel id
            }
        }
Exemplo n.º 6
0
 public async Task DeleteAsync(Floor floor)
 {
     _db.Remove(floor);
     await _db.SaveChangesAsync();
 }
Exemplo n.º 7
0
 public async Task DeleteAsync(Location location)
 {
     _db.Remove(location);
     await _db.SaveChangesAsync();
 }
Exemplo n.º 8
0
 public void Remove(T entity)
 {
     _context.Remove(entity);
 }